由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - ask a question about compile shared library using libtool
相关主题
关于C++ STL编译的疑问vc 2008: compilation error about header file
forward declarationsize of structure
how to split function declaration and implementation in C#最初级的白痴C++问题
Question about friend in C++C语言重复定义问题
请教有关header file的几个问题macro and std:: function name clashing
which header file declares ntohs() in c++ ?tr1,问题
一道面试怪题C++. (转载)基础问题:在header里面define function
关于Makefile的一个问题怎么样最好的编译不同文件在同一个VC project里面?
相关话题的讨论汇总
话题: shared话题: library话题: function
进入Programming版参与讨论
1 (共1页)
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
1 (共1页)
进入Programming版参与讨论
相关主题
怎么样最好的编译不同文件在同一个VC project里面?请教有关header file的几个问题
Qt Creatorwhich header file declares ntohs() in c++ ?
qeustion about separation of interface and implementation in java一道面试怪题C++. (转载)
菜鸟求助:怎么自动include header file?关于Makefile的一个问题
关于C++ STL编译的疑问vc 2008: compilation error about header file
forward declarationsize of structure
how to split function declaration and implementation in C#最初级的白痴C++问题
Question about friend in C++C语言重复定义问题
相关话题的讨论汇总
话题: shared话题: library话题: function