I have already done a research about JNI,and I think I understand how it works, but I've been trying to call to a C function from another C func called by JNI.
我已经对JNI做了一个研究,我想我理解它是如何工作的,但我一直试图从JNI调用的另一个C函数调用一个C函数。
I have 2 .c
, HelloWorld and HelloWorld2, and a java program to call HelloWorld. HelloWorld at the same time calls to a function defined in HelloWold2 but this causes an error when executing.
我有2个.c,HelloWorld和HelloWorld2,以及一个调用HelloWorld的java程序。 HelloWorld同时调用HelloWold2中定义的函数,但这会在执行时导致错误。
java: symbol lookup error: /home/hduser/Desktop/final2/libhello.so: undefined symbol: helloworld
java:符号查找错误:/home/hduser/Desktop/final2/libhello.so:undefined symbol:helloworld
1 个解决方案
#1
1
Assuming that you have two files:
假设你有两个文件:
HelloWorld.c HelloWorld2.c
and HelloWorld is supposed to call something from HelloWorld2 you can:
和HelloWorld应该从HelloWorld2中调用一些东西,你可以:
- put both into the same shared lib
- put both into separate shared lib and make sure HelloWorld is linked with HelloWorld2
将两者放入同一个共享库中
将两者放入单独的共享库中,并确保HelloWorld与HelloWorld2链接
Make sure that shared libraries are visible by setting LD_LIBRARY_PATH.
通过设置LD_LIBRARY_PATH确保共享库可见。
You can find some JNI samples here: http://jnicookbook.owsiak.org/
你可以在这里找到一些JNI样本:http://jnicookbook.owsiak.org/
#1
1
Assuming that you have two files:
假设你有两个文件:
HelloWorld.c HelloWorld2.c
and HelloWorld is supposed to call something from HelloWorld2 you can:
和HelloWorld应该从HelloWorld2中调用一些东西,你可以:
- put both into the same shared lib
- put both into separate shared lib and make sure HelloWorld is linked with HelloWorld2
将两者放入同一个共享库中
将两者放入单独的共享库中,并确保HelloWorld与HelloWorld2链接
Make sure that shared libraries are visible by setting LD_LIBRARY_PATH.
通过设置LD_LIBRARY_PATH确保共享库可见。
You can find some JNI samples here: http://jnicookbook.owsiak.org/
你可以在这里找到一些JNI样本:http://jnicookbook.owsiak.org/