对于不遵循 libNAME.so 命名约定的库,如何在不使用 -l 或硬编码路径的情况下使用 GCC 进行链接?

How to link using GCC without -l nor hardcoding path for a library that does not follow the libNAME.so naming convention?(对于不遵循 libNAME.so 命名约定的库,如何在不使用 -l 或硬编码路径的情况下使用 GCC 进行链接?) - IT屋-程序员软件开发技术
本文介绍了对于不遵循 libNAME.so 命名约定的库,如何在不使用 -l 或硬编码路径的情况下使用 GCC 进行链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个共享库,我希望使用 GCC 链接可执行文件.共享库有一个非标准名称,不是 libNAME.so 形式,所以我不能使用通常的 -l 选项.(它恰好也是一个 Python 扩展,因此没有lib"前缀.)

I have a shared library that I wish to link an executable against using GCC. The shared library has a nonstandard name not of the form libNAME.so, so I can not use the usual -l option. (It happens to also be a Python extension, and so has no 'lib' prefix.)

我可以将库文件的路径直接传递给链接命令行,但这会导致库路径被硬编码到可执行文件中.

I am able to pass the path to the library file directly to the link command line, but this causes the library path to be hardcoded into the executable.

例如:

g++ -o build/bin/myapp build/bin/_mylib.so

有没有办法链接到这个库而不导致路径被硬编码到可执行文件中?

Is there a way to link to this library without causing the path to be hardcoded into the executable?

推荐答案

:"前缀允许您为库指定不同的名称.如果你使用

There is the ":" prefix that allows you to give different names to your libraries. If you use

g++ -o build/bin/myapp -l:_mylib.so other_source_files

应该在您的路径中搜索 _mylib.so.

should search your path for the _mylib.so.

这篇关于对于不遵循 libNAME.so 命名约定的库,如何在不使用 -l 或硬编码路径的情况下使用 GCC 进行链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)