Linux 库链接问题 - HADOOP HDFS C API
我正在尝试运行 C API 库附带的 hdfs_test 应用程序。当我使用以下命令编译应用程序时:
gcc myTest.c -I/usr/HDFS/src/c++/libhdfs -L/usr/HDFS/build/c++/Linux-i386-32/lib -lhdfs -o myTest
我在设置 LD_LIBRARY_PATH 后执行此操作,
export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/i386:/usr/lib/jvm/default-java/jre/lib/i386/server:/usr/lib/jvm/default-java/jre/lib/i386/libjava.so
但收到以下错误:
/usr/HDFS/build/c++/Linux-i386-32/lib/libhdfs.so: undefined reference to `JNI_GetCreatedJavaVMs'
/usr/HDFS/build/c++/Linux-i386-32/lib/libhdfs.so: undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status
我看到了这篇文章: Linux 库问题, 我认为这可能是相关的,即使我没有收到“未找到库”的警告。
提前致谢
I am trying to run the hdfs_test application that comes alongside the C API library. When I'm compiling the application using the command:
gcc myTest.c -I/usr/HDFS/src/c++/libhdfs -L/usr/HDFS/build/c++/Linux-i386-32/lib -lhdfs -o myTest
I do that after setting the LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/usr/lib/jvm/default-java/jre/lib/i386:/usr/lib/jvm/default-java/jre/lib/i386/server:/usr/lib/jvm/default-java/jre/lib/i386/libjava.so
I'm getting the following error:
/usr/HDFS/build/c++/Linux-i386-32/lib/libhdfs.so: undefined reference to `JNI_GetCreatedJavaVMs'
/usr/HDFS/build/c++/Linux-i386-32/lib/libhdfs.so: undefined reference to `JNI_CreateJavaVM'
collect2: ld returned 1 exit status
I saw this post:
linux library problem,
and I thought it might be relevant, even though I'm not getting a "library not found" warning.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信您的编译命令中缺少
-ljava
。I believe a
-ljava
is missing in your compilation command.您需要链接 libhdfs 和 libjvm!
我想最好的帮助方法就是向您展示一个工作设置。这是我的 Makefile 中的“LIBS”:
您想使用“-Wl,-rpath”,因此不需要使用 LD_LIBRARY_PATH。这是链接后的 ldd 结果。您希望确保所有库都已解析:
当您运行它时,由于它最终运行 Java 字节代码,因此您还需要设置 CLASSPATH。您可以执行以下操作:
这是一个迟到的答案,但我希望它可以为其他人节省一些麻烦。
You need to link with both libhdfs and libjvm!
I guess the best way to help is to show you a working setup. Here is my 'LIBS' in my Makefile:
You want to use "-Wl,-rpath" so you don't need to use LD_LIBRARY_PATH. And here is the ldd result after linking. You want to make sure all libraries are resolved:
When you run it, since it eventually runs Java byte code, you also need to set CLASSPATH. Here is what you can do:
It's a late answer, but I hope it can save other people some trouble.