I am currently developing a C library for a client and to do so I needed to use other libraries like: glib2.0, libxml2, lib, openssl and gmp. After I finished my development and created the .so I tried to compile a test program with it and found out that my library was not self-contained and that I needed to link the program with all those other libraries I mentioned above.
The client insist that he wants either a dll or a .so product and that it should be self contained, just one file so his application can consume it, the same way that he does with other libraries.
I am not sure what to do, it there a way to produced this self contained .so? If not possible what other options do I have? I am developing in solaris 11 and the target system is a Solaris server.
Thank you very much.
Makefile code:
# C compiler
CC = gcc
# C flags
CFLAGS = -fPIC -O3 -g
# linking flags
LDFLAGS = -shared
LDLIBS = $(shell xml2-config --cflags --libs) $(shell pkg-config --cflags --libs glib-2.0) -lssl -lcrypto -lm -lgmp -lz
# target lib
TARGET_LIB = libservices.so
SRCS = lib1.c lib2.c lib3.c lib4.c # source files
OBJS = $(SRCS:.c=.o)
# Compilation
.PHONY: all
all: ${TARGET_LIB}
$(TARGET_LIB): $(OBJS)
${CC} ${LDFLAGS} $(OBJS) -o ${TARGET_LIB}
# pull in dependency info for *existing* .o files
-include $(OBJS:.o=.d)
# Compiles and Generates Dependency Info
%.o: %.c
gcc $(CFLAGS) -c $*.c -o $*.o ${LDLIBS}
gcc -MM $(CFLAGS) $*.c > $*.d
Example output of test code compilation
gcc -I/path/to/libservices -L/path/to/libservices services_test.c -o test -lservices
libservices.so: undefined reference to `EVP_CipherInit'
libservices.so: undefined reference to `g_free'
libservices.so: undefined reference to `xmlFreeDoc'
libservices.so: undefined reference to `g_str_equal'
libservices.so: undefined reference to `g_hash_table_lookup'
libservices.so: undefined reference to `__gmpz_get_str'
libservices.so: undefined reference to `EVP_CIPHER_CTX_block_size'
libservices.so: undefined reference to `xmlCheckVersion'
libservices.so: undefined reference to `EVP_EncryptFinal'
libservices.so: undefined reference to `g_hash_table_new'
libservices.so: undefined reference to `EVP_CIPHER_CTX_init'
libservices.so: undefined reference to `xmlNodeGetContent'
libservices.so: undefined reference to `xmlCleanupParser'
libservices.so: undefined reference to `__gmpz_pow_ui'
libservices.so: undefined reference to `EVP_EncryptUpdate'
libservices.so: undefined reference to `__gmpz_clear'
libservices.so: undefined reference to `xmlParseDoc'
libservices.so: undefined reference to `g_hash_table_insert'
libservices.so: undefined reference to `EVP_DecryptInit_ex'
libservices.so: undefined reference to `EVP_EncryptInit_ex'
libservices.so: undefined reference to `g_hash_table_destroy'
libservices.so: undefined reference to `g_list_free'
libservices.so: undefined reference to `EVP_DecryptFinal'
libservices.so: undefined reference to `g_str_hash'
libservices.so: undefined reference to `__gmpz_init_set_str'
libservices.so: undefined reference to `EVP_DecryptUpdate'
libservices.so: undefined reference to `EVP_CipherFinal'
libservices.so: undefined reference to `__gmpz_sizeinbase'
libservices.so: undefined reference to `xmlDocGetRootElement'
libservices.so: undefined reference to `g_hash_table_foreach'
libservices.so: undefined reference to `EVP_CIPHER_CTX_cleanup'
libservices.so: undefined reference to `EVP_CipherUpdate'
collect2: error: ld returned 1 exit status
If I link it with the other libraries doing:
gcc -I/path/to/libservices -L/path/to/libservices servicios_test.c -o test -lservices -lssl -lcrypto -lm -lgmp -lz `pkg-config --cflags --libs glib-2.0` `xml2-config --cflags --libs`
And then add the path using:
export LD_LIBRARY_PATH=/path/to/libservices:$LD_LIBRARY_PATH
the test code works fine.