DLLs, shared objects, and makefiles

This section contains two sample makefiles. The first is an example of a traditional Open Server makefile for Solaris, which contains routines, such as main and srv_run, used to build an executable. The second makefile is used to build dynamic libraries for use with EAServer. The main() logic has been moved to an init handler.

In addition to the sample makefiles there are instructions for building shared objects for UNIX and DLLs for Windows.

Traditional Open Server makefile for Solaris

# A makefile that builds the Open Server executable, server
# server.exe on Windows.## The main() function is in server.c.## The two files, handler1.c and handler2.c implement all the handlers, and
# compile into a static library, handler.a (handler.lib on Windows).## All the remaining code is in files appl1.c and appl2.c, and compiles into a
# static library, appl.a (appl.lib on Windows).#CFLAGS=				-I$(SYBASE)/include -I.LIBS=				-lsrv -lblk -lct -ltcl -lcs -lcomn -lintl -lm -lnsl -ldlLDFLAGS=				-L$(SYBASE)/lib $(LIBS)server:				server.o handler.a appl.a				$(LINK.c) -o 	$@ server.o handler.a appl.ahandler.a:				handler1.o handler2.o				$(AR) $(ARFLAGS) $@ handler1.o handler2.oappl.a:				appl.o				$(AR) $(ARFLAGS) $@ appl.o.c.o:				$(COMPILE.c) $(OUTPUT_OPTION) $<

Makefile for EAServer

# Build a dynamic library, server.so (server.dll on Windows), instead of an
# executable.
#There is no main() function anymore: the applicable main() logic is in 
# the init handler function. The file is still server.c.
#
# The two files, handler1.c and handler2.c, implement all the handlers and
# compile into a dynamic library, handler.so (handler.dll on Windows).
# Register each handler in EAServer Manager.
#
# All the remaining code is in files appl.c, and compiles into a
# static library, appl.a (appl.lib on Windows). No change here.#No need to link with libraries.
CFLAGS=					-I$(JAGUAR)/include -I.

server.so:					server.o handler.so appl.a
					$(LINK.c) -G -o $@ server.o handler.so appl.a

handler.so			:		handler1.o handler2.o
					$(LINK.c) -G -o $@ handler1.o handler2.o

appl.a:					appl.o
					$(AR) $(ARFLAGS) $@ appl.o

.c.o:
					$(COMPILE.c) $(OUTPUT_OPTION) $<

Building shared objects on Solaris

When building shared objects on Solaris compile all the modules with the compile switches -KPIC -mt

The following link line should be used when creating a shared object on Solaris. Note that EAServer libraries have a “j” prefix in them, for example, libjsrv_r.so:

 ld -g -o <shared object name> <object files> -ljsrv_r -ljct_r -ljcs_r\
-ljtcl_r -ljcomn_r -ljintl_r -ljtml_r -Bdynamic -lnsl -ldl -lthread -lm

Building DLLs on Windows

When building DLLs on Windows use the compile flags:

CFLAGS = /W3 /MD /nologo /Z7 /Od /DWIN32 /Gz

You need to export all handler functions. Use a .def file for this purpose and specify this .def file /def link option. For example:

# Definition file dependencies
LIBRARY sample     INITINSTANCE
DESCRIPTION  'EAServer event Handler'
HEAPSIZE      22000
PROTMODE
CODE LOADONCALL EXECUTEREAD NONCONFORMING
DATA PRELOAD READWRITE MULTIPLE NONSHARED
EXPORTS
connect_handler

NoteTo run a server using an event-handler DLL, the directory containing the DLL must be specified in the PATH environment variable.