防止gcc链接器使用system/lib64文件夹中的非系统库 [英] Keep gcc linker from using non-system libraries found in system /lib64 folder

查看:263
本文介绍了防止gcc链接器使用system/lib64文件夹中的非系统库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将一个大型C ++库(libcoro.so)和示例应用程序(coro-example.cpp)从Windows移植到RedHat Linux 7.4.我在Linux上的开发经验很少,因此这可能是一个新手"问题.我有libcoro和示例应用程序在我的RHEL 7.4 VM上进行编译,链接和运行.但是,当客户尝试将coro-example.o链接到libcoro.so时,gcc链接器无法将其链接到客户的RHEL 7.4计算机上.错误消息是:

I am porting a large C++ library (libcoro.so) and example application (coro-example.cpp) from Windows to RedHat Linux 7.4. I have very little development experience on Linux, so this is probably a 'newbie' question. I have libcoro and the example app compiling, linking, and running on my RHEL 7.4 VM. However, the gcc linker fails to link the app on the customer's RHEL 7.4 machine when he tries to link coro-example.o to libcoro.so. The error message is:

/usr/bin/ld:警告:./bin/libcoro.so所需的libusb-0.1.so.4不是 找到(尝试使用-rpath或-rpath-link)
libcoro.so:未定义 引用"usb_open"
libcoro.so:未定义的引用 'usb_release_interface'
... etc ...

/usr/bin/ld: warning: libusb-0.1.so.4, needed by ./bin/libcoro.so not found (try using -rpath or -rpath-link)
libcoro.so: undefined reference to 'usb_open'
libcoro.so: undefined reference to 'usb_release_interface'
...etc...

在我的机器上运行"ldd coro.so"时显示:

Running 'ldd coro.so' on my machine displays:

libusb-0.1.so.4 =>/lib64/libusb-0.1.so.4(0x00007f71115db000)
...等...

libusb-0.1.so.4 => /lib64/libusb-0.1.so.4 (0x00007f71115db000)
...etc...

在客户的机器上:

libusb-0.1.so.4 =>找不到
[许多其他库] =>找不到
... etc ...

libusb-0.1.so.4 => not found
[many other libs] => not found
...etc...

确实,这些库位于我的/lib64文件夹中,但不在客户的文件夹中.我不确定它们是如何安装在我的计算机上的.我可以访问缺少的库,并可以将它们与libcoro.so库一起提供.我真的希望我的应用程序是独立的,并且可以在任何RHEL 7.x机器上运行.我的问题是:

Indeed, these libraries are in my /lib64 folder, but are not in the customer's. I'm not sure how they got installed on my machine. I have access to the missing libraries and can deliver them with my libcoro.so library. I really want my app to be self-contained and run on any RHEL 7.x machine. My question is:

确定哪些库不属于RHEL 7.x安装的一部分,并且如果我不提供本地副本,则链接器在我的计算机上失败的最佳方法是什么?我尝试使用-nodefaultlibs进行链接,但是在诸如printf()之类的函数上链接失败,并且我还没有找到找到这些标准库的方法.它们似乎不在/lib64中.

What is the best way to identify which libraries are not part of the RHEL 7.x installation and have the linker fail on my machine if I'm not delivering a local copy? I tried linking with -nodefaultlibs, but the link fails on functions like printf() and I haven't found a way to locate these standard libraries. They don't appear to be in /lib64.

是否可以从默认库搜索中排除/lib64?

Is there a way to exclude /lib64 from the default library search?

推荐答案

有一个链接器开关-Wl,--no-undefined似乎可以满足我的要求.链接失败并生成错误,因为该库未明确命名.另外,命令ldd libcoro.so列出了所有依赖关系以及在哪里解析它们.我也发现这篇文章非常有帮助.

There is a linker switch -Wl,--no-undefined which seems to do what I want. It fails to link and generates an error is the library is isn't explicitly named. Also, the command ldd libcoro.so lists all dependencies and where they are being resolved. I also found this this article very helpful.

这篇关于防止gcc链接器使用system/lib64文件夹中的非系统库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆