如何在GCC中链接不是以lib开头的库文件? [英] How do I link a library file in GCC that does not start with lib?

查看:480
本文介绍了如何在GCC中链接不是以lib开头的库文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我用ld链接libm之类的库时,我需要删除lib前缀.如果文件不遵循此命名约定怎么办?除了重命名文件之外,还有其他方法可以链接吗?

When I link a library such as libm in with ld, I need to drop the lib prefix. What if the file does not follow this naming convention? Is there a way to link it other than renaming the file?

推荐答案

您可以针对任何库进行链接,例如foo.a,通过在链接行上指定完整路径:

You can link against any library, e.g. foo.a, by specifying full path to it on the link line:

gcc main.o /path/to/foo.a

链接库搜索非标准库名会给您带来的损失,例如这将不起作用:

What you lose with non-standard library name is the ability for the linker to search for it, e.g. this will not work:

gcc main.o -L/path/to foo.a

您可以使用-l:foo.a语法避免搜索不足:

You can avoid that lack of search by using -l:foo.a syntax:

gcc main.o -L/path/one -L/path/two -l:foo.a

当我用ld链接libm之类的库时

When I link a library such as libm in with ld

请注意,通常,您应该ld链接任何内容.请改用编译器驱动程序-它会将链接和链接添加到正确结果中所需的对象和库.

Note that in general you should not link anything with ld. Use the compiler driver instead -- it adds objects and libraries to the link line that are required for correct result.

这篇关于如何在GCC中链接不是以lib开头的库文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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