码海拾遗

但行好事,莫问前程

导航

compile with -fPIC

在新公司工作第四天,依然要编译FFmpeg,不同的是难度大了,以前遇到什么参数编译不过的,就去掉,因为不是专业做视频的,但是新公司绕不过了。

编译FFmpeg动态库的时候发现链接某些静态库的时候会报错:

relocation R_X86_64_32S against `cmnMemAlloc' can not be used when making a shared object; recompile with -fPIC

基础不扎实,不知道make的时候还可以添加参数,查了很多资料,最后从一个回答中试出解决方案:

再编译存在问题的库时,调用“make”命令的时候,添加“CFLAGS='-fpic'”参数,就可以了。

举个栗子:

我编译FFmpeg时报这样的错:

/usr/bin/ld: /usr/local/lib/libvo-amrwbenc.a(wrapper.o): relocation R_X86_64_32S against `cmnMemAlloc' can not be used when making a shared object; recompile with -fPIC

意思是链接的“libvo-amrwbenc.a”库需要添加“-fPIC”重新编译,那我就在编译“libvo-amrwbenc.a”时,调用

make CFLAGS='$CFLAGS -fpic'

有的./configure 时也有这样的参数“CFLAGS”,也可以在这里添加

 

编译动态库要链接静态库才会出现这问题,编译静态库链接静态库则不会

有个回答如是说:

The solution was to compile everything with -fPIC, and link shared objects with -shared.

Add -fPIC to CFLAGS or CXXFLAGS for make-based projects.

posted on 2017-04-20 16:02  widrin  阅读(6402)  评论(0编辑  收藏  举报