g++, ld and JNI - linking problem
I have two 3rd party library files called libA.a and libB.a
They are built with g++.
Now, I need to do function calls from java using JNI.
I have a JNI wrapper file called wrapper.cpp and tried to created a library.so file which can be loaded into my java program and do function calls.
I first compiled wrapper.cpp using g++ and tried to link all object files using ld.
These are the commands I used.
%g++ wrapper.cpp -I /usr/java/include/ -I /usr/java/include/solaris/ libA.a libB.a -L /lib/*.so -c
This created wrapper.o
%ld -L /usr/java/lib/ -L /lib/ -b wrapper.o libA.a libB.a -o wrapper.so -m
This gives me the following error:
Undefined first referenced
symbol 开发者_如何学C in file
_ZNKSsixEj wrapper.o
_ZNSt8ios_base4InitD1Ev wrapper.o
_ZNSt8ios_base4InitC1Ev wrapper.o
__gxx_personality_v0 wrapper.o
_ZNKSs4sizeEv wrapper.o
ld: fatal: Symbol referencing errors. No output written to wrapper.so
Googling these errors does not help :(
Can someone please tell me where am I going wrong?
Note: I am using g++ 3.4.3 on SunOS 5.10
Try adding -lstdc++ to your linker command. You might also need --enable-auto-import.
Using clang++. -lstdc++ does not have the _ZNSt8ios_base4InitC1Ev symbol defined. Try adding the library -lgnustl_shared to your linker command. That worked for me.
精彩评论