-
problem creating .so
Hi!
In my project, I have to make a .so . In order to create the .so, I also need to compile some files:
this is how the makefile looks like:
CC = g++
FLAGS_FPIC = -fPIC -m32 -I$(APP_INCL) -I$(CSI_INCL) -I$(MQ_INCL) -g
(APP_INCL, CSI_INCL, MQ_INCL are paths to my .h files.)
then, to create the .o files, i use:
Bind.o: $(APP_SRC)/Bind.c
$(CC) -c $(FLAGS_FPIC) $(APP_SRC)/Bind.c
Init.o: $(APP_SRC)/Init.c
$(CC) -c $(FLAGS_FPIC) $(APP_SRC)/Init.c
.......
to create the .so then, I use:
FLAGS_SO_LIBS = -L$(CSI_LIB) \
-lcsi_hlclient \
-lcsi_report \
-lm
FLAGS_SO = -m32 -shared $(FLAGS_SO_LIBS) -lc -W1
$(CC) $(FLAGS_SO),-soname,libZziCsiLib32.so.1 -o libZziCsiLib32.so.1.0.1 Bind.o Init.o Connect.o Put.o Get.o Disconnect.o Term.o
When I try compiling, the compiler compiles the .c files, creates the .so, but when i try to compile the test class, where I use the library, it doesn't seem to see the functions, declared in the .h files , included to compile the .c files
Any idea?
Thanks, Rok
-
How are you linking your test app?
--
Mats
-
Hi!
My testApp iz compiled like this:
g++ -m32 SiEcnGetTest.o -L. -L/app/csi/lib -lcsi_hlclient -lcsi_report -lm -lc -lZziCsiLib32 -o SiEcnGetTest
-
I take it you have around your headers?
If you post (an example of if there are many) the error message(s) you get, we can probably help better.
--
Mats
-
g++ -m32 SiEcnGetTest.o -L. -L/app/csi/lib -lcsi_hlclient -lcsi_report -lm -lc -lZziCsiLib32 -o SiEcnGetTest
--------------------------------------------------------------------------------------------------------------
SiEcnGetTest.o: In function `main':
SiEcnGetTest.c:(.text+0x295): undefined reference to `ccn_get'
./libZziCsiLib32.so: undefined reference to `HL_init_sec_context(tagCSISECINFO*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_bind(char*, char*, tagCSIQOS*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_decode(tagCSIDD*, long, char*, tagCSIDD*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_get_q_depth(long, long, long*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_mq_open(long, tagCSIMQOD*, long, long*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `App_Init'
./libZziCsiLib32.so: undefined reference to `HL_encode(tagCSIDD*, char*, long, char*, tagCSIDD*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_alloc(unsigned long, tagCSIDD**, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_free(tagCSIDD**, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_mq_conn(char*, long*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_mq_browse(long, long, tagCSIMQMD*, tagCSIMQGMO*, tagCSIDD*, long*, tagCSIQOS*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `App_Term'
./libZziCsiLib32.so: undefined reference to `HL_delete_sec_context(long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_mq_put(long, long, tagCSIMQMD*, tagCSIMQPMO*, tagCSIDD*, tagCSIQOS*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_unbind(long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_mq_disc(long*, long*, long*)'
./libZziCsiLib32.so: undefined reference to `App_Disconn'
./libZziCsiLib32.so: undefined reference to `App_PutMessage'
./libZziCsiLib32.so: undefined reference to `HL_mq_close(long, long*, long, long*, long*)'
./libZziCsiLib32.so: undefined reference to `HL_gettype(tagCSIDD*, char*, long*, char*, long*, long*)'
collect2: ld returned 1 exit status
is "extern C" that much of a big deal regarding this problem?
-
I'd say what you are seeing is directly an extern "C" problem - the reason I say that is that in C code functions, you never get a printout of the function arguments and return type - because the linker doesn't know that. In C++ compiled code, the basic function name is "decorated" with type information, so that for example
Code:
int blah(long a, int b)
{
}
may result in a name like this:
It's probably not quite so obvious, but it's the principle of how it works.
When you use extern "C", you tell the compiler "These functions are compiled as C rather than C++, so don't decorate them with C++ style return type and parameter information". [But in 10 characters]
--
Mats
-
Ok - i didn't have the "export C" in only one header file.. put it in there, but the problem remains the same - when trying to run the test, using the .so, the compiler doesnt seem to find some methods, in the headers, needed by the .c files.. Any other ideas?
-
where is (as an example) HL_init_sec_context declared and where is it defined? It appears to come from the .so file, if I read the error listing right. Is it imported from another library? If so, does the header file for THAT file have extern "C" in it? If not, and you can't change that header file, wrap the include itself with extern "C".
--
Mats