To compile your UDF, you must specify appropriate settings for your compiler.
If you are on Microsoft Windows and are using Microsoft's Visual Studio, please do the following:
#include "c8udf.h" // Ensure functions are "exported" properly from dll. #if defined(_MSC_VER) #define USER_FUNCTION_EXPORT __declspec( dllexport ) #else // defined(_MSC_VER) #define USER_FUNCTION_EXPORT #endif // defined(_MSC_VER) extern "C" { USER_FUNCTION_EXPORT void my_function(C8Udf* ctx); }; // extern "C"
You will need to customize the names and return types of each UDF and any intermediate function, if you have one.
To do this, go to the menu, click on "Project" and then on "Properties". You should get a new window titled something like MySample Property Pages.
In the left-hand pane of this window, click on "Configuration Properties", then "", and then on "General".
The right-hand pane should now show a list of settings that you can modify.
Click in the field to the right of Additional Include Directories and add the directory that contains the file c8udf.h file which is included with the Sybase CEP product.
On Microsoft Windows, this directory is typically:
C:\Program Files\SybaseC8\Server\sdk\c\include
On 64-bit Microsoft Windows, this directory is typically:
C:\Program Files (x86)\SybaseC8\Server\sdk\c\include
You can also add other directories if necessary for your UDF.
To do this, 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.
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_server_lib.lib
You do not need to enter the complete path; entering the file name is sufficient.
To double check that you haven't skipped a step, you can look at the "Command Line" for the C/C++ compiler and the Command Line for the Linker. This shows 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 "C/C++" 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" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_USRDLL" /D "TEST_UDF_AGGR1_EXPORTS" /D "_UNICODE" /D "UNICODE" /D "_WINDLL" /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, 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 below.)
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\E2\C_SDK\TAggr1\TAggr1\Debug\TAggr1.dll" /INCREMENTAL /NOLOGO /LIBPATH:"C:\Program Files\SybaseC8\Server\sdk\c\lib" /DLL /MANIFEST /MANIFESTFILE:"Debug\TAggr1.dll.intermediate.manifest" /SUBSYSTEM:WINDOWS /MACHINE:X86 /ERRORREPORT:PROMPT c8_sdk_server_lib.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 should be ready to compile.
C:\Program Files\SybaseC8\Server\bin C:\Program Files\SybaseC8\Server\plugins C:\Program Files\SybaseC8\Studio\plugins
If you are using a command line compiler such as cc, you can use a make file or a script file.
TARGET=libc8_udf_regexp_match.so all: $(TARGET) OBJECTS = regexp_match.o regexpr2.o syntax2.o C8 = /home/henry/sybasec8 SDK_PATH = $(C)/server/sdk/c INC = -I$(SDK_PATH)/include -I$(SDK_PATH)/include/stlport C8_LIB = -L$(SDK_PATH)/lib -lc8_sdk_server_lib -lstlport CPPFLAGS = -fPIC -shared %.o : %.cpp gcc $(INC) $(CPPFLAGS) $< -o $@ $(TARGET) : $(OBJECTS) gcc -o $@ $?
You cannot copy this and use it directly. In addition to customizing the file names, you will also have to replace blank spaces with tab characters in appropriate places to satisfy the make program.
If you are compiling for a x86 architecture, you will probably also want to use the -m64 flag or equivalent.
cc -I${HOME}/sybasec8/server/sdk/c/include \ -o libmma.so \ -L${HOME}/sybasec8/server/sdk/c/lib/ \ -lc8_sdk_server_lib \ -fPIC \ -shared \ mma.cpp
where mma.c is the name of your source code file and libmma,so is the name you'd like to use for the library file.
-I specifies the directory(s) to be searched for #include files.
-o specifies the name of the output file. Typically, this is a shared library file.
-L specifies the directory(s) to search for library files that need to be linked with this one.
-l specifies the name of the Sybase CEP library to link with to use the functions.
-fPIC specifies that the compiler should generate Position-Independent Code, or code for dynamic linking.
-shared specifies that the output will be a shared object library file as opposed to a stand-alone executable program.
Although on UNIX-like operating systems your library file name will typically be of the form libXYZ.so, your .udf file should specify only "mma" as the library name; do not specify "libmma.so" in the .udf file. The .udf file interpreter will make platform-specific adjustments for the filename extension (.so vs. .dll) and, if necessary, add an initial "lib" prefix.
If you are compiling for a 64-bit x86 architecture, you will probably also want to use the -m64 flag or equivalent.
/home/<userid>/sybasec8/server/bin
/home/<userid>/sybasec8/server/plugins
/home/<userid>/sybasec8/studio/plugins