如何获得ang来链接库而没有“lib”字首? [英] How to get clang to link against a library without the "lib" prefix?

查看:233
本文介绍了如何获得ang来链接库而没有“lib”字首?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是我有一个没有lib前缀的库。我想链接到它,我不能重新编译它(它实际上是一个Python模块)。

My situation is I have a library that doesn't have a "lib" prefix. I'd like to link against it, and I can't recompile it (it's actually a Python module).

现在,如果使用'-l'标志使用GCC或clang,则会自动添加lib前缀,并且未找到库。对于GCC,我可以使用-l:mylib.so来链接到任意文件。

Now, if you use the '-l' flag with GCC or clang, then the lib prefix is automatically added and the library is not found. For GCC, I can use '-l:mylib.so' to get it to link against an arbitrary file.

但是,这对clang不起作用。

However, this doesn't work for clang. Is it possible to get clang to link against a particular library without the 'lib' prefix?

推荐答案

这回答了问题,但是,从一个有点不同的角度。请参阅相关问题 C ++ 11代码编译与` clang ++,但不与clang -x c ++

This answers the question, but from a somewhat different angle. See the related question C++ 11 code compiles with `clang++`, but not with `clang -x c++`.

gcc documention 说明:


对象文件根据文件内容由链接器与库区分开来。

Object files are distinguished from libraries by the linker according to the file contents.

em>工作,如果你使用 clang ++ -x c ++ 。相反,库文件被作为一个C ++源文件,这会产生一百万左右的编译错误。您不能将库文件放在 -x c ++ 之前,因为所需的符号不会被链接。

This does not work if you use clang++ -x c++. Instead, the library file is taken as a C++ source file, and this generates a million or so compile errors. And you can't put the library file before the -x c++, because the needed symbols won't be linked in.

一个明显的解决方案是重命名您的源文件以具有 .cpp 扩展名,因此 -x 开关不必要(或使用符号链接)。

One obvious solution is to rename your source files to have a .cpp extension, so the -x switch is unnecessary (or use symbolic links). But this might be a pain to add to your build system.

另一个与OP的问题直接相关的解决方案是通过flags指定库:

Another solution, directly related to the OP's question, is to specify the library via the flags:

    -L. -l:mylib.foo

如果库不在本地目录中,请将< c $ c>。。

If the library is not in the local directory, change the dot . accordingly.

这篇关于如何获得ang来链接库而没有“lib”字首?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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