直接告诉gcc静态链接一个库 [英] Telling gcc directly to link a library statically

查看:111
本文介绍了直接告诉gcc静态链接一个库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 -Wl,-Bstatic 为了告诉 gcc 我想要哪个库,感觉很奇怪与静态链接。毕竟我直接告诉 gcc 所有关于链接库的其他信息( -Ldir -bibname )。



是否可以直接告诉gcc驱动程序直接链接哪些库?



澄清:我知道如果某个库仅存在于静态版本中,它将使用它而不使用 -Wl,-Bstatic ,但我想暗示 gcc 来选择静态库。我也知道直接指定库文件会与它链接,但我更愿意将包含静态库和动态库的语义保持一致。

解决方案

当然,使用 -l:代替 -l <​​/ code>是可能的。例如 -l:libXYZ.a libXYZ.a 链接。注意 lib 写出来,而不是 -lXYZ ,它会自动扩展为 libXYZ


It feels strange to me to use -Wl,-Bstatic in order to tell gcc which libraries I want to link with statically. After all I'm telling gcc directly all other information about linking with libraries (-Ldir, -llibname).

Is it possible to tell the gcc driver directly which libraries should be linked statically?

Clarification: I know that if a certain library exists only in static versions it'll use it without -Wl,-Bstatic, but I want to imply gcc to prefer the static library. I also know that specifying the library file directly would link with it, but I prefer to keep the semantic for including static and dynamic libraries the same.

解决方案

It is possible of course, use -l: instead of -l. For example -l:libXYZ.a to link with libXYZ.a. Notice the lib written out, as opposed to -lXYZ which would auto expand to libXYZ.

这篇关于直接告诉gcc静态链接一个库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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