Developer's-Panther WebSphere


Appendix C. Adding C Functions

This appendix discusses how to make C functions that you write available to EJBs.


How to Add C Functions for EJB Access

  1. Compile the C functions into a shared library (.dll or .so).
  2. Create a JPL file with calls to sm_slib_load and sm_slib_install to install and load the new shared library.
  3. Save the JPL file in a Panther application library accessible to the WebSphere application server process, such as server.lib. (To see what application libraries are available, check the SMFLIBS setting in panther.ini.)
  4. Edit panther.ini and add the JPL file to the SMINITJPL setting in the EJB Globals section.

    Note: SMINITJPL in panther.ini must only be used to call sm_slib_load and sm_slib_install. All other JPL commands are unavailable.

  5. Make the shared library available to the system.

    For UNIX, add the shared library to LD_LIBRARY_PATH (Solaris) or LIBPATH (AIX).

    For Windows, add the DLL to the working directory, the Windows system directory, or the PATH.

  6. Your C functions are added to the global funclist whenever EJBs initialize Panther on the application server.

Building DLL's using MSVC 6 on Windows

  1. Create a new project. Select FileNew. Select Project TabWin32 Dynamic-Link Library.
  2. Enter the name of your DLL for the project name.
  3. Write your C code in the .cpp file created with your project in the Source Files. (This is in the FileView tab on the left frame of MSVC.)
  4. Include the correct header files such as smmach.h and smproto.h. The include statements for these header files have to be added to the StdAfx.h file in Header Files in the File View frame.
  5. Now the include directory for these header files have to be added to the project. Select ToolsOptionsDirectories tab. Make sure that Show Directories For is set to Include files. (You can either double click in the window to add a new entry, or click on the yellow box.)
  6. You should also include the directory for your lib files. This is the same as step 5, except for Show Directories For should be set to Library files.
  7. Now you should specify the .lib files you need to include in the project. Select ProjectSettingsLink TabObject/Library Files. Add the names of your libraries here. You may also need to add the files themselves to the project. Select ProjectAdd to ProjectFiles.
  8. Create a .def file to export your functions. The .def file should just contain the Keyword EXPORT and then the name of your functions following it. Add the .def file to the project. Same as previous step to add lib files to project.
  9. Necessary compile and linking options must be specified. Select ProjectSettingsC/C++ tab. Add /DWIN32_EJB to Project Options.
  10. Create the DLL by selecting BuildBuild DLLName.

Building Shared Libraries (.so) on UNIX

.so -- shared libs, statements in {} have to be modified.

  1. Write your C code.
  2. Write a .def file to export your functions.
  3. Compile with following options:
    -lpthread -D_REENTRANT -D__EXTENSIONS__ -G -L{path_to_panther_lib_directory} -l{library_file}  -I{include_other_files_such_as_.def_file} -D{PLAT_NAME}  -o {my_.so_file}

An example compile line for UNIX is:

acc -lpthread -D_REENTRANT -D__EXTENSIONS__ -G
-L/usr/prolifics/prlwassv425/lib -lPanSmEJB
-Imy_dll.def -DSOLARIS2_6 -o libMyShared.so my_shared.c

Here is a very simple .def file for the function isit_there.

my_dll.def:
EXPORT
isit_there