g***l 发帖数: 2753 | 1 Sorry, no Chinese input here.
I met a strange issue when creating a shared library using libtool.
In this project,I am using two C files, base.c and base2.c, and one H header
file,base.h, to create libbasefunc.so. All the function declarations are
done in the header file and the function implementations are done in these
two C files.
In another project, some functions in libbasefunc.so will be called in other
C files which are used to create another shared library libinstance.so.
The main application will uses libinstance.so to do something.
The problem is :
If I put all the function implementations in only one c file, and generate
libbasefunc.so. and generate libinstance.so using -lbasefunc option,
everything is fine.The main application can use libinstance.so smoothly.
However, if I put the function implementations into two different C files
and all the function declarations in one header file, I can create the
libbasefunc.so and libinstance.so without any issues, but when the
application uses libinstance.so, it will report "undefined symbol: your_test
_func2". Actually "your_test_func2()" is declared in the header file and
implemented in base2.c.
Here is the copy of the Makefile.am
basefunc_LTLIBRARIES = libbasefunc.la
# sources used to compile this plug-in
libbasefunc_la_SOURCES = base.c base2.c
# flags used to compile this plug-in
# add other _CFLAGS and _LIBS as needed
libbasefunc_la_CFLAGS = $(GLIB_CFLAGS)
libbasefunc_la_LIBADD = $(GLIB_LIBS)
libbasefunc_la_LDFLAGS = $(GLIB_LDFLAGS)
libbasefunc_la_LIBTOOLFLAGS = --tag=disable-static
# headers we need copy to ${prefix}/include
include_HEADERS = base.h
#=========End of Makefile.am =======================
lately, I found that if I add another option "--tag=disable-shared" to
libbasefunc_la_LIBTOOLFLAGS, everything will be fine. The application can
use libinstance.so correctly. But there will be no shared library
libbasefunc.so generated, instead a statically linked library libbasefunc.a
was created. This is not what I want.
I have used nm command to check the symbol table in libbasefunc.so, actually
symbol "your_test_func2" was in the code section with a valid address. I
just don't understand why it works only if we put all the source code into
one file.
Would you please input some words to help me to fix this issue?
I want to put the function implementations into two different files and
still want to create a usable shared library libbasefunc.so.
thanks |
|