Compiling and Linking the Example

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.

Compiling Using Visual Studio in Microsoft Windows

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.

  1. Start Microsoft Visual Studio.
  2. Create a project file by going to the menu and clicking on File -> New -> Project.
    1. Click on the [+] to expand "Visual C++ " Project Types.
    2. Click on "Win32 Console Application".
    3. In the "Name:" field, fill in the name that you'd like to use for your project.
    4. In the "Location:" field, browse and specify the directory where you want project to be stored.
    5. Click OK.
    6. The next window to appear is the "Win32 Application Wizard" window. Click on "Finish".
  3. Microsoft Visual Studio creates a simple C++ (.cpp) file to use as a starting point. Remove all the contents of this file and then insert your own code for the adapter.

    Make sure your file includes the following:

    #include <nspr.h> 
    	#include "c8adapter.h" 
    	#include "c8client.h" 
    	#include "c8conversions.h" 
    	#include "c8messages.h"
    
  4. If you have other C-language source files that you need, add them to the project
  5. Update several settings that are available in the "Property Pages" for this project:
    1. Update the list of directories to search for #include files:
      1. Go to the menu, click on "Project" and then on "MySample Properties". This opens a new window named "MySample Property Pages" or similar.
      2. In the left-hand pane of this window, click on "Configuration Properties", then on , and then on "General". The right-hand pane should now show a list of settings that you can modify.
      3. Click in the field to the right of "Additional Include Directories" and add the directories listed below. On Microsoft Windows, these directories are typically:
      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:

      1. Click in the "Additional Include Directories" field, and paste in the first path.

      2. 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.

    2. Turn off precompiled headers. Go to the left-hand pane in the "Property Pages" window, click on "" and then on "Precompiled headers", then click on "Create/Use Precompiled Header" and set it to "Not Using Precompiled Headers".
    3. Add the library files. Go to the left-hand pane of the "Property Pages" window, click on "Linker" and then on "General".

      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
      
    4. Add a dependency on the c8_sdk_client_lib.lib file. To do this, go to the left-hand pane of the "Property Pages" window, click on "Linker" and then on "Input".

      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.

  6. To compile, use the appropriate option on the "Build" menu, for example, "Build MySample".
  7. To execute the file that you have created, you must ensure that your PATH environment variable includes the directories that contain the .dll files that the adapter needs. Typically, these directories are:
    C:\Program Files\SybaseC8\Server\bin
    	C:\Program Files\SybaseC8\Server\sdk\c\lib
    

Compiling Using the Command Line in Microsoft WIndows

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.

  1. Configure your C compiler so that you can compile and link at least a simple C program (for example, a "hello world" program). A sample script that sets environment variables is available later in this section.

    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
    
  2. Update your INCLUDE environment variable to include the following directories:
    C:\Program Files\SybaseC8\Server\sdk\c\include\
    	C:\Program Files\SybaseC8\Server\sdk\c\include\nspr
    
  3. Update your LIB environment variable to include the following directory:
    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
    
  4. When you execute the program, included the following files:
    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
    
  5. On Microsoft Windows, execute "cl" (Compile and Link) commands like those shown below:
    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
    

Compiling and Linking on UNIX-like Operating Systems

This section explains how to compile and link the example code on UNIX-like operating systems.

  1. Configure your C compiler (for example, gcc) so that you can compile and link at least a simple C program (for example, a "hello world" program).

    Set the environment variables PATH, INCLUDE, and LIB appropriately.

  2. Update your LIB environment variable to include the proper library directory. If you have the Sybase CEP Engine installed under the directory "/home/<userid>" then the paths will be:
    /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.

  3. Make sure that your PATH environment variable includes the cirrecr by executing the following commands:
    
    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.

  4. Compile and link:
    # 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.