gcc -fPIC

linux 下面用gcc 生成一个动态库。

发现总是报" recompile with -fPIC" 这个错误,因为项目是用cmake配置出来的,所以以为自己配置"-fPIC" 配置错了。

所以捣鼓了半天也没捣鼓好,最后搜到下面一段文字。

You try to link a static library to a shared library. Shared library
code must be
position independent. Therefore every object file has to be built with
-fPIC. This
also includes the object files inside your static library.

You have two options
 * build libftgl.a yourself with -fPIC.
 * link libftgl.so to your library - then you have FTGL as a runtime dependency

因为我的动态库又调用了另外一个静态库。按照上面的解释,所有的动态库连接用到的库都需要加"-fPIC" 编译选项。

把用到的那个库加上"-fPIC", 重新编译了一次,okay了!

看来对-fpic这个理解还是不到位。

https://blog.youkuaiyun.com/sinc00/article/details/44833839

https://blog.youkuaiyun.com/derkampf/article/details/69660050

https://www.cnblogs.com/leo0000/p/5691483.html

抽时间再好好研究下这个东西。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值