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
抽时间再好好研究下这个东西。。。