1

I'm trying to compile c++ script using cmake3 but unfortunately i'm getting this error:

...
 /usr/lib/gcc/x86_64-redhat-linux/4.8.5/../../../libswresample.a(resample.o): relocation R_X86_64_32 against `.rodata' can not be used whenmaking a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
gmake[2]: *** [libstreammuxer.so] Error 1
gmake[1]: *** [CMakeFiles/streammuxer.dir/all] Error 2
gmake: *** [all] Error 2

Before same thing error occurred when i was installing ffmpeg but as soon i as add "--disable-static --enable-shared" to the configure it was able to compile successfully but i could not get it same to work this in streammuxer app script too using cmake.

This is the command i used

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/bin/streamMuxer -DCMAKE_BUILD_TYPE=Release ../ && cmake --build . --target install
General Omosco
  • 606
  • 1
  • 10
  • 20
  • 1
    The **first error** is common one `recompile with -fPIC`. You need to have `swresample` library compiled with `-fPIC` or build your main project without `-fPIC`. There are plenty questions on Stack Overflow on this topic. – Tsyvarev Jun 24 '20 at 07:43
  • Wow it took me 24hours digging why before! Thanks it works now by recompiling the libraries with -fPIC by enabling shared "--enable-shared", – General Omosco Jun 24 '20 at 11:59
  • Does this answer your question? [Libsourcey missing -fPIC compilation error](https://stackoverflow.com/questions/45145419/libsourcey-missing-fpic-compilation-error). -- It looks like both "re-compile with `-fPIC`" and "`--enable-shared`" solutions are mentioned here. – Kevin Jun 24 '20 at 12:24
  • Another common solution to rebuild with `-fPIC` is shown [here](https://stackoverflow.com/q/26549137/3987854), although with modern CMake, it really should be `target_compile_options(YourTarget PRIVATE -fPIC)`. – Kevin Jun 24 '20 at 12:30
  • 1
    @squareskittles even w/ not so modern CMake it should be done via `set(CMAKE_POSITION_INDEPENDENT_CODE ON)` – zaufi Jun 24 '20 at 20:35

0 Answers0