4

I have created an .so file in which I am not at all using the boost library (Of course earlier I used it), but later I switched to pthreads and removed all the header files and boost .so file linking from the makefile.

The java files are getting compiled successfully. But, when I try to run using

java -Djava.library.path=libs/ -cp build/ Send

it gives me the following error.

Exception in thread "main" java.lang.UnsatisfiedLinkError: /home/aahmed/libplxmsg-java/libs/libplxmsgjavaasyncbinder.so: /home/aahmed/libplxmsg-java/libs/libplxmsgjavaasyncbinder.so: undefined symbol: _ZN5boost6system16generic_categoryEv

I am sure that I am not using any boost related libraries or header files. Even the link for the .so file is given correctly.

EDIT

On executing nm on the .so file which was being loaded. Small snipped of that.

00000000002044d8 b _ZN5boost6system10errno_ecatE 00000000002044e0 b _ZN5boost6system11native_ecatE 00000000000031a0 W _ZN5boost6system12system_errorD0Ev 00000000000033a0 W _ZN5boost6system12system_errorD1Ev 0000000000003180 W _ZN5boost6system14error_categoryD0Ev 0000000000003050 W _ZN5boost6system14error_categoryD1Ev 00000000002044d0 b _ZN5boost6system14posix_categoryE U _ZN5boost6system15system_categoryEv U _ZN5boost6system16generic_categoryEv 0000000000003060 W _ZN7JNIEnv_14CallVoidMethodEP8_jobjectP10_jmethodIDz 00000000000030f0 W _ZN7JNIEnv_9NewObjectEP7_jclassP10_jmethodIDz U _ZN9__gnu_cxx18__exchange_and_addEPVii@@GLIBCXX_3.4 0000000000003240 W _ZNK5boost6system12system_error4whatEv 0000000000003030 W _ZNK5boost6system14error_category10equivalentERKNS0_10error_codeEi 0000000000002fe0 W _ZNK5boost6system14error_category10equivalentEiRKNS0_15error_conditionE 0000000000002fd0 W _ZNK5boost6system14error_category23default_error_conditionEi

Chaitanya
  • 3,399
  • 6
  • 29
  • 47
  • 2
    perform an `nm` on the `.so` file and verify the fact that it isn't using boost because that error message implies that it needs it. – Anya Shenanigans Apr 03 '13 at 13:07
  • I ran that command on the `.so` file, it was giving some boost related symbols. But, I am not at all using any boost libraries or even header files during the compilation and even during linking. What causes this error ? How to avoid it ? (Just attached a small snippet of output from executing `nm` command.) – Chaitanya Apr 04 '13 at 13:00
  • Without a copy of the build script (makefile? bjam file?) it's just guesswork. I would recommend removing all `.so` and `.o` files and rebuild the library, checking for the boost libraries - there may be a stray file from a previous build – Anya Shenanigans Apr 04 '13 at 13:11
  • I m deleting all the `.o` files and `.so` files during each and every clean. You say that there is still some file which is using that boost library ? – Chaitanya Apr 04 '13 at 13:42
  • The most simple way avoid this error is to link with `Boost.System` (`-lboost_system`). – Igor R. Apr 04 '13 at 14:00
  • Yes, that is what appears to be the case. You can run `nm` on each of the individual `.o` files that makes up the `.so` file in the hopes of tracking it down. Again, you need to be methodical with this - check what `.o`, `.a` files make up the `.so` - know for certain - it may be linking a library that has a boost dependency; examine each of these `.o` files individually – Anya Shenanigans Apr 04 '13 at 14:46
  • @IgorR. I tried linking the `-lboost_system`, but it was giving error like `libboost_system.so.1.50.0: cannot open shared object file: No such file or directory`. I am giving correct path to the so file. – Chaitanya Apr 05 '13 at 07:04

1 Answers1

3

Make sure to create your shared library (one that is used from Java) such it is linked with boost. For example:

g++ -g -shared -fpic -L$(BOOST)/lib \
-lboost_system -I$(JAVA_HOME)/include \
-I$(JAVA_HOME)/include/linux \
your_code.c -o libyourcode.so

This way, your JNI code will be properly linked with boost.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45