Hi everyone,
I am encountering a problem while linking a shared library with GCC 4.1 on linux.
I have written a static library (implementing some utils function), containing utils.h and utils.cpp
Here is the part of the makefile creating the static lib named libutils.a :
I'm making a test exe , which makefile is :
And a shared library to use with JNI :
Both the test exe and the jni shared library work perfectly.
Now (here comes the problem ...) I want to add a new file to my libutils.a, so I modify the makefile to :
This should be the only thing I have to modify. However now the test exe runs perfectly, but JNI does not want.
After some investigations, I found that two of the functions from string_utils I use in the jni shared library are undefined :
However, doing nm -s on libutils.a gives :
I've been looking for any error but couldn't find anything. I'm sure it is a small thing, but I cannot see it. Hope you would light me up
Thanks
nutzzz
I am encountering a problem while linking a shared library with GCC 4.1 on linux.
I have written a static library (implementing some utils function), containing utils.h and utils.cpp
Here is the part of the makefile creating the static lib named libutils.a :
Code:
libutils.a: utils.o
ar -r $@ $^
ranlib $@
utils.o: utils.h utils.cpp
g++ -static-libgcc -Wall -ansi -I. -o $@ -c utils.cpp
I'm making a test exe , which makefile is :
Code:
main_test: test_utils.o libutils.a
test_utils.o: test_utils.h test_utils.cpp
g++ -static-libgcc -Wall -ansi -I. -o $@ -c test_utils.cpp
And a shared library to use with JNI :
Code:
libjniutils.so: jni_utils.o
g++ -shared -o $@ $^ ./libutils.a
jni_utils.o: jni_utils.h jni_utils.cpp
g++ -static-libgcc -Wall -ansi -I. -o $@ -c jni_utils.cpp
Both the test exe and the jni shared library work perfectly.
Now (here comes the problem ...) I want to add a new file to my libutils.a, so I modify the makefile to :
Code:
libutils.a: utils.o string_utils.o
ar -r $@ $^
ranlib $@
utils.o: utils.h utils.cpp
g++ -static-libgcc -Wall -ansi -I. -o $@ -c utils.cpp
string_utils.o: string_utils.h string_utils.cpp
g++ -static-libgcc -Wall -ansi -I. -o $@ -c string_utils.cpp
This should be the only thing I have to modify. However now the test exe runs perfectly, but JNI does not want.
After some investigations, I found that two of the functions from string_utils I use in the jni shared library are undefined :
Code:
dev@rantanplan:~/DEV$ ldd -d libjniutils.so
undefined symbol: _ZN11StringUtils4trimERKSsS1_ (libjniutils.so)
undefined symbol: _ZN11StringUtils7toUpperERKSs (libjniutils.so)
linux-gate.so.1 => (0xffffe000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0xb7cdc000)
libm.so.6 => /lib/tls/i686/cmov/libm.so.6 (0xb7cb7000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xb7cac000)
libc.so.6 => /lib/tls/i686/cmov/libc.so.6 (0xb7b7b000)
/lib/ld-linux.so.2 (0x80000000)
However, doing nm -s on libutils.a gives :
Code:
dev@rantanplan:~/DEV$ nm -s libutils.a | grep StringUtils
_ZN11StringUtils7toUpperERKSs in string_utils.o
_ZN11StringUtils7toLowerERKSs in string_utils.o
_ZN11StringUtils8trimLeftERKSsS1_ in string_utils.o
_ZN11StringUtils9trimRightERKSsS1_ in string_utils.o
_ZN11StringUtils4trimERKSsS1_ in string_utils.o
0000030c T _ZN11StringUtils4trimERKSsS1_
000000ba T _ZN11StringUtils7toLowerERKSs
00000000 T _ZN11StringUtils7toUpperERKSs
00000174 T _ZN11StringUtils8trimLeftERKSsS1_
0000020a T _ZN11StringUtils9trimRightERKSsS1_
I've been looking for any error but couldn't find anything. I'm sure it is a small thing, but I cannot see it. Hope you would light me up
Thanks
nutzzz