关于编译C++程序链接静态库出现can not be used when making a PIE object; recompile with -fPIE错误的问题

首先说一下解决方法:编译时添加-no-pie选项即可

问题原因:简单来说就是GCC当前会默认生成PIE(Position Independent Execuable) 代码,无法与非PIE的库(许多静态库)进行链接。

PIE原理可以参看这个blog:关于Linux下gcc 编译 C 源文件时,生成的是Shared object file而不是Executable file

posted @ 2022-05-04 18:13  Woate  阅读(12261)  评论(0)    收藏  举报