linux库问题

发布于 2024-11-03 12:56:40 字数 956 浏览 0 评论 0原文

外面的每个人, 我正在编写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

锦上情书 2024-11-10 12:56:40

尝试添加:

-L/usr/java/lib

到您的链接器命令,因为您的链接器无法找到该库:I_GetCreatedJavaVMs@SUNWprivate_1.1

一点建议:乱搞LD_LIBRARY_PATH并不是一个好主意。只需修复您的链接器命令即可。

Try adding:

-L/usr/java/lib

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.

清风无影 2024-11-10 12:56:40

链接器发出有关未找到对函数 JNI_CreateJavaVM@SUNWprivate_1.1 的引用的警告

/usr/bin/ld:警告:libhdfs.so:未定义的引用
`JNI_CreateJavaVM@SUNWprivate_1.1'

此函数名称可能特定于 Sun/Oracle HotSpot JVM 中的库。其他 JVM 可能有其他名称。例如,我的 OpenJDK 只有较短的名称,例如 JNI_CreateJavaVM,并且链接器给了我同样的警告。

您可以通过运行命令从 libjvm.so 获取函数列表:

readelf -s libjvm.so | grep JNI_CreateJavaVM # given that you are in catalog containing libjvm.so

如果输出不包含所需的函数,那么您可能需要安装另一个 JDK。

Linker gives a warning about not found reference to function JNI_CreateJavaVM@SUNWprivate_1.1

/usr/bin/ld: warning: libhdfs.so: undefined reference to
`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:

readelf -s libjvm.so | grep JNI_CreateJavaVM # given that you are in catalog containing libjvm.so

If output does not contain required function, then you might want to install another JDK.

这对我有用:

CDH=/opt/cloudera/parcels/CDH
OS_ARCH=amd64

gcc hdfs_example.c -I$CDH/include -L$CDH/lib64 \
       -L/usr/java/default/jre/lib/${OS_ARCH}/server \
       -ljvm -lhdfs -o hdfs_write_test

That's what worked for me:

CDH=/opt/cloudera/parcels/CDH
OS_ARCH=amd64

gcc hdfs_example.c -I$CDH/include -L$CDH/lib64 \
       -L/usr/java/default/jre/lib/${OS_ARCH}/server \
       -ljvm -lhdfs -o hdfs_write_test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文