简体   繁体   English

链接器在Eclipse / JNI / ANT中找不到lib

[英]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. 我正在尝试在Linux下的Eclipse中构建一个涉及JNI和ANT的大型Java / c ++项目。 One of the source c++ files calls the log10() function for mathematical calculations. 一个源c ++文件调用log10()函数进行数学计算。 The project compiles fine, but fails at linking, where it complains that it cannot find the libm.so library necessary to link log10() . 该项目可以正常编译,但是无法链接,它抱怨找不到链接log10()所需的libm.so库。

My problem is that I am unable to properly tell Eclipse to link that file, even after the following steps: 我的问题是,即使经过以下步骤,我也无法正确地告诉Eclipse链接该文件:

  1. Added the correct library path in the linker options, 在链接器选项中添加了正确的库路径,
  2. Added a reference to libm in the linker include list, 在链接器包含列表中添加了对libm的引用,
  3. Added -lm to the full compile options list, 在完整的编译选项列表中添加了-lm
  4. Set LD_LIBRARY_PATH to point to the library's location, LD_LIBRARY_PATH设置为指向库的位置,
  5. Copied the library to the current directory. 将库复制到当前目录。

What am I doing wrong/has anyone had such experiences with correctly linking libs in Eclipse? 我在做什么错/有人在Eclipse中正确链接库有这样的经历吗? Any suggestions? 有什么建议么?

This is a bit confusing. 这有点令人困惑。 If you fail to find your library at runtime inside your java environment : 如果您无法在Java环境中的运行时找到您的库,请执行以下操作:

Try loading your .so library inside the java environment before making any calls to log10. 在对log10进行任何调用之前,请尝试在Java环境中加载.so库。

System.LoadLibrary("m");

Notice how I left "lib" and ".so" out. 注意我如何将“ lib”和“ .so”排除在外。

However, you are complaining of a Linker problem from C++, you cannot link to a dynamic file. 但是,您在抱怨C ++中的链接器问题,因此无法链接到动态文件。 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). 您只能链接到静态库或静态导出库(因此,需要在编译时链接到libm.a文件,然后程序在运行时将需要libm.so)。

Could you post the exact message you are receiving and when you are receiving it ? 您能否张贴您收到的确切消息以及何时收到?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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