如何使用 -fPIC 重新编译

2021-12-18 00:00:00 gcc ffmpeg compilation c++ fpic

我试图在我的 ARM Ubuntu 上按照这个指南重新安装我的 ffmpeg机器.不幸的是,当我编译一个使用这个库的程序时,我得到了以下失败:

I was trying to reinstall my ffmpeg, following this guide, on my ARM Ubuntu machine. Unfortunately, when I compile a program which uses this lib I get the following failure:

/usr/bin/ld: /usr/local/lib/libavcodec.a(amrnbdec.o): relocation R_ARM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libavcodec.a: could not read symbols: Bad value
collect2: ld returned 1 exit status

现在我想用 -fPIC 重新编译它,就像编译器建议的那样,但我不知道如何.任何帮助表示赞赏.

Now I would like to recompile it with -fPIC like the compiler is suggesting but I have no idea how. Any help is appreciated.

推荐答案

简而言之,该错误意味着您不能使用静态库与动态库链接.正确的做法是把一个libavcodec编译成一个.so而不是.a,这样另一个.so> 您尝试构建的库可以很好地链接.

Briefly, the error means that you can't use a static library to be linked w/ a dynamic one. The correct way is to have a libavcodec compiled into a .so instead of .a, so the other .so library you are trying to build will link well.

这样做的最短方法是在 ./configure 选项中添加 --enable-shared.或者您甚至可以尝试完全禁用共享(或静态)库……您选择适合您的库!

The shortest way to do so is to add --enable-shared at ./configure options. Or even you may try to disable shared (or static) libraries at all... you choose what is suitable for you!

相关文章