This section explains how to compile and link the example code on Microsoft Windows and UNIX-like operating systems. In Microsoft Windows, the example can be compiled and linked either from inside Visual Studio or from the command line. In UNIX-like operating systems, the example can be compiled and linked from within a C compiler.
This section explains how to compile and link on Microsoft Windows from inside Visual Studio. These instructions assume that you are using Microsoft Visual Studio 2005.
Make sure your file includes the following:
#include <nspr.h> #include "c8adapter.h" #include "c8client.h" #include "c8conversions.h" #include "c8messages.h"
C:\Program Files\SybaseC8\Server\sdk\c\include\ C:\Program Files\SybaseC8\Server\sdk\c\include\nspr
On Microsoft Windows, the directories are typically:
C:\Program Files (x86)\SybaseC8\Server\sdk\c\include C:\Program Files (x86)\SybaseC8\Server\sdk\c\include\nspr
You can add other directories if necessary for your adapter:
Click in the "Additional Include Directories" field, and paste in the first path.
Click on the ellipsis ("..."), click on the folder icon (the tool tip will refer to this as "new line"), and then enter the next path.
Repeat step "b" as many times as necessary to add the remaining required paths.
In the field to the right of "Additional Library Directories", add the directory that contains the library.
On 32-bit Microsoft Windows, this directory is typically:
C:\Program Files\SybaseC8\Server\sdk\c\lib
On Microsoft Windows, this directory is typically:
C:\Program Files (x86)\SybaseC8\Server\sdk\c\lib
In the field to the right of "Additional Dependencies", enter
c8_sdk_client_lib.lib nspr4.lib
(Note that you do not need to enter the complete path of either of these libraries; entering the file names is sufficient.)
If you are using Microsoft's Visual C development and environment and you'd like to double check that you haven't skipped a step, you can look at the Command Line for the compiler and the Command Line for the Linker. These show the command-line parameters passed from Microsoft's GUI IDE to the command-line compiler and linker.
To view the command line for the compiler, go to the left-hand pane of the Property Pages window, click on "" and then click on Command Line. The command line should look similar to the following:
/Od /I "C:\Program Files\SybaseC8\Server\sdk\c\include\nspr" /I "C:\Program Files\SybaseC8\Server\sdk\c\include\\" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Gm /EHsc /RTC1 /MDd /Fo"Debug\\" /Fd"Debug\vc80.pdb" /W3 /nologo /c /Wp64 /ZI /TP /errorReport:prompt
If you set the warning level to a value other than 3, then the "/W3" will be different.
The command line may or may not include
/D "_DEBUG"
If the command line includes this, you may only be able to use the .DLL on a computer that has the debug version of the C runtime library. For more information, see the Troubleshooting section.
To view the command line for the linker, go to the left-hand pane of the Property Pages window, click on "Linker" and then click on "Command Line". The command line should look similar to the following:
/OUT:"C:\c8test\E3\SDKC\TESTAdapter1.2\TESTAdapter1.2\Debug\TESTAdapter1.2.exe" /INCREMENTAL /NOLOGO /LIBPATH:"C:\Program Files\SybaseC8\Server\sdk\c\lib" /MANIFEST /MANIFESTFILE:"Debug\TESTAdapter1.2.exe.intermediate.manifest" /DEBUG /PDB:"c:\c8test\e3\sdkc\testadapter1.2\testadapter1.2\debug\TESTAdapter1.2.pdb" /SUBSYSTEM:CONSOLE /MACHINE:X86 /ERRORREPORT:PROMPT c8_sdk_client_lib.lib nspr4.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib
Now that you have entered all the project properties, click the "OK" button on the "Property Pages" window.
At this point, you are ready to compile.
C:\Program Files\SybaseC8\Server\bin C:\Program Files\SybaseC8\Server\sdk\c\lib
This section explains how to compile and link the example code on Microsoft Windows by using the command line. These instructions assume that you are using the compiler that comes with Microsoft Visual Studio 2005.
To ensure that you can access the MS Visual Studio 2005 resources such as library files you will typically need to set the environment variables PATH, INCLUDE, and LIB appropriately. Set these variables by running the vcvars32.bat script provided by Microsoft with Visual Studio:
C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat
C:\Program Files\SybaseC8\Server\sdk\c\include\ C:\Program Files\SybaseC8\Server\sdk\c\include\nspr
C:\Program Files\SybaseC8\Server\sdk\c\lib
This allows the compiler/linker to find the required .lib files when linking.
To do this, execute the following command:
set LIB=%LIB%;C:\Program Files\SybaseC8\Server\sdk\c\lib
C:\Program Files\SybaseC8\Server\sdk\c\lib C:\Program Files\sybasec8\server\bin
This allows the program to find the .dll (Dynamic Link Library) files or .so (Shared Object) files at runtime.
To do this, execute the following commands:
set PATH=%PATH%;C:\Program Files\SybaseC8\Server\sdk\c\lib set PATH=%PATH%;C:\Program Files\SybaseC8\Server\bin
rem Compile and link the C Adapter SDK example rem program, which uses the Adapter API. cl example_input_adapter.c c8_sdk_client_lib.lib nspr4.lib
Below is a sample Microsoft Windows .bat file to configure the environment for compiling and running the C Adapter SDK example with the Microsoft Visual Studio .NET 2005 development environment.
@echo off rem ------------------------------------------------------------------- rem PURPOSE: The purpose of this file is to configure the environment rem so that we can compile stream adapters, which require that rem we have the NSPR (Netscape Portable Runtime) files, which rem include .h and library files that we need. rem This assumes that you have installed rem Microsoft Visual Studio .NET 2005 to the directory rem C:\Program Files\Microsoft Visual Studio 8 rem and have already run the vcvars32.bat script. rem ------------------------------------------------------------------- rem --- Set the env vars to enable us to find the C8 .h files rem --- and the NSPR .h files. set INCLUDE=C:\Program Files\SybaseC8\Server\sdk\c\include;%INCLUDE% set INCLUDE=C:\Program Files\SybaseC8\Server\sdk\c\include\nspr;%INCLUDE% rem --- Set the env vars to enable us to find the Sybase library files set LIB=C:\Program Files\SybaseC8\Server\sdk\c\lib\;%LIB% rem Needed for SSL. rem NOTE TO READER: The following should all be on one rem line, not split across lines. set INCLUDE=C:\Program Files\SybaseC8\Server\sdk\c\include\nss\public;%INCLUDE% rem --- Make sure that the PATH contains the .DLL files. set PATH=%PATH%;c:\Program Files\SybaseC8\Server\bin set PATH=%PATH%;c:\Program Files\SybaseC8\Server\sdk\c\lib
This section explains how to compile and link the example code on UNIX-like operating systems.
Set the environment variables PATH, INCLUDE, and LIB appropriately.
/home/<userid>/sybasec8/server/sdk/c/lib
To update your LiBenvrionment variable, execute the following command:
export LIB=${LIB}:/home/<userid>/sybasec8/server/sdk/c/lib
This allows the compiler/linker to find the required .lib files when linking.
export PATH=${PATH}:/home/<userid>/sybasec8/server/sdk/c/lib export PATH=${PATH}:/home/<userid>/sybasec8/server/bin
This allows the program to find the .so (Shared Object) files at runtime.
# Compile the bulk of the code and link all the # pieces together. Note that the command below # should all be on one line, even if # it is displayed as multiple lines. gcc -Wl,--allow-shlib-undefined -I${INCLUDE1} -I${INCLUDE2} -L${LIB1} -L${LIB2} myAdapter.c ${LIB1}/libc8_sdk_client_lib.so
Below is a sample shell script to configure the environment for compiling and running the C Adapter SDK example. Customize this file to specify the userid. If you do not have the Sybase CEP Engine installed in "/home/<userid>" you will need to make additional customizations. (The example assumes that you are using gcc on linux).
# PURPOSE: # Set up the environment so that we can compile an # out-of-process adapter. echo "Don't forget to 'source' this script" echo "(for example, with the '.' command) " echo "rather than simply run it." # Include the standard C/C++ SDK files. # We'll use this environment variable later when we compile. export INCLUDE1=/home/<userid>/sybasec8/server/sdk/c/include # Include additional files needed for out-of-process adapters. # We'll use this environment variable later when we compile. export INCLUDE2=/home/<userid>/sybasec8/server/sdk/c/include/nspr export LIB1=/home/<userid>/sybasec8/server/sdk/c/lib export LIB2=/home/<userid>/sybasec8/server/bin export PATH=$PATH:$LIB1:$LIB2 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIB1:$LIB2
Below is a sample shell script to compile and link the adapter. Customize this file to specify the program name; we used "myAdapter" below. (The example below assumes that you are using gcc on linux).
# PURPOSE: # Compile and link the out-of-process adapter. # This script is for UNIX-like operating systems. echo "This assumes that you already ran set_adapter_env.bat, " echo "which sets the INCLUDE and LIB env vars." # Compile the bulk of the code and link all the pieces together. # Note that the command below should all be on one line, even if # it is displayed as multiple lines. gcc -Wl,--allow-shlib-undefined -I$INCLUDE1 -I$INCLUDE2 -L${LIB1} -L${LIB2} myAdapter.c ${LIB1}/libc8_sdk_client_lib.so # Give the executable file whatever name you want. mv a.out myAdapter
The "--allow-shlib-undefined" command tells the gcc compiler to proceed even if it can't find all the library files it needs. The required library files are in the PATH or the LD_LIBRARY_PATH and will be resolved at runtime.