linux库问题
外面的每个人, 我正在编写 c 代码,当我编译它时有一个奇怪的问题。 源码没问题。 我使用以下选项编译它:
$ gcc above_sample.c -I/home/hadoop/project/hadoop-0.20.2/src/c++/libhdfs -L/home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib -lhdfs -o above_sample.
但它显示的输出如下:
/usr/bin/ld: warning: libjvm.so, needed by /home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so, not found (try using -rpath or -rpath-link) /home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so: undefined reference to `JNI_CreateJavaVM@SUNWprivate_1.1'
/home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so: undefined reference to `JNI_GetCreatedJavaVMs@SUNWprivate_1.1'
collect2: ld returned 1 exit status
我搜索了 libjvm.so 我在我的系统中的 /usr/java/lib 中找到了它。
我做了一个符号链接,但没有用。
我将库复制到了几个地方,例如 usr/lib 检查 LD_library_Path 但无法编译程序,它一次又一次地显示相同的错误
有人能告诉我我做错了什么吗? 如何将 .so 文件链接到 gcc ? 或者.so文件如何在程序中链接?
Everybody out there,
I'm writing a c code which have a strange problem when I compile it .
The source code is OK.
I compile it with following option:
$ gcc above_sample.c -I/home/hadoop/project/hadoop-0.20.2/src/c++/libhdfs -L/home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib -lhdfs -o above_sample.
But it show the out put like that:
/usr/bin/ld: warning: libjvm.so, needed by /home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so, not found (try using -rpath or -rpath-link) /home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so: undefined reference to `JNI_CreateJavaVM@SUNWprivate_1.1'
/home/hadoop/project/hadoop-0.20.2/c++/Linux-amd64-64/lib/libhdfs.so: undefined reference to `JNI_GetCreatedJavaVMs@SUNWprivate_1.1'
collect2: ld returned 1 exit status
I searched for libjvm.so i found It in my system in /usr/java/lib.
I made a symbolic link of it but did not work.
i copied the library in to several places like usr/lib check the LD_library_Path
but could not manage to compile the program it showing the same error again and again
Can any one tell me what I'm doing wrong ?
how to link .so file to gcc ?
or how .so files are linked in program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试添加:
到您的链接器命令,因为您的链接器无法找到该库:
I_GetCreatedJavaVMs@SUNWprivate_1.1
。一点建议:乱搞
LD_LIBRARY_PATH
并不是一个好主意。只需修复您的链接器命令即可。Try adding:
To your linker command, since that's the library your linker is not being able to find:
I_GetCreatedJavaVMs@SUNWprivate_1.1
.A little piece of advice: it's not a good idea to mess with
LD_LIBRARY_PATH
. Just fix your linker command.链接器发出有关未找到对函数 JNI_CreateJavaVM@SUNWprivate_1.1 的引用的警告
此函数名称可能特定于 Sun/Oracle HotSpot JVM 中的库。其他 JVM 可能有其他名称。例如,我的 OpenJDK 只有较短的名称,例如 JNI_CreateJavaVM,并且链接器给了我同样的警告。
您可以通过运行命令从 libjvm.so 获取函数列表:
如果输出不包含所需的函数,那么您可能需要安装另一个 JDK。
Linker gives a warning about not found reference to function JNI_CreateJavaVM@SUNWprivate_1.1
This function name might be specific for library from Sun/Oracle HotSpot JVM. Other JVMs may have another name. For example, mine OpenJDK had only shorter name such as JNI_CreateJavaVM and linker gave me the same warning.
You may get list of the functions from your libjvm.so by running command:
If output does not contain required function, then you might want to install another JDK.
这对我有用:
That's what worked for me: