简体   繁体   中英

Linker can't find lib in Eclipse/JNI/ANT

I am trying to build a large Java/c++ project involving JNI and ANT in Eclipse, under Linux. One of the source c++ files calls the log10() function for mathematical calculations. The project compiles fine, but fails at linking, where it complains that it cannot find the libm.so library necessary to link log10() .

My problem is that I am unable to properly tell Eclipse to link that file, even after the following steps:

  1. Added the correct library path in the linker options,
  2. Added a reference to libm in the linker include list,
  3. Added -lm to the full compile options list,
  4. Set LD_LIBRARY_PATH to point to the library's location,
  5. Copied the library to the current directory.

What am I doing wrong/has anyone had such experiences with correctly linking libs in Eclipse? Any suggestions?

This is a bit confusing. If you fail to find your library at runtime inside your java environment :

Try loading your .so library inside the java environment before making any calls to log10.

System.LoadLibrary("m");

Notice how I left "lib" and ".so" out.

However, you are complaining of a Linker problem from C++, you cannot link to a dynamic file. You can only link to a static library, or a static export library (so you need a libm.a file to which to link at compile time, and then your program will require libm.so at runtime).

Could you post the exact message you are receiving and when you are receiving it ?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM