Peter
Peter

Reputation: 11890

Building shared library with ffmpeg results in relocation error

I need to create a custom shared library that internally uses ffmpeg functions. The idea is to create one fat shared library, say, myffmpeg.so.

I first build ffmpeg code (3.3.1 as of this post). During configuration, I specify -fPIC via --extra-cflags and --extra-cxxflags. I also specify -enable-pic during the configuration. After running configure and make, various archive files such as libswscale.a, libavformat.a, etc. are successfully created.

Next, I try to build my shared library:

gcc -fPIC -Ixxx  mywrapper.cpp 
gcc -shared -o myffmpeg.so mywrapper.o -Lxxx -lswscale -lavformat...

However, this results in an error:

Relocation R_X86_64_PC32 against symbol ff_M24A can not be
used when making a shared object; 

Looks like I am missing some compiler/linker setting. Can someone please point me in the right direction? Regards.

Upvotes: 3

Views: 1308

Answers (2)

Peter
Peter

Reputation: 11890

Here is how I solved the problem. You need to add "-Wl,-Bsymbolic" to ldflags during configuration. Also, when you create the shared library, you need to pass the same parameter to the linker. Regards.

Upvotes: 3

halfelf
halfelf

Reputation: 10107

If you need shared libraries, build ffmpeg with --enable-shared, which will generate shared objects libswscale.so, libavformat.so, etc. The .a files are static libraries built by default configuration.

Upvotes: 0

Related Questions