Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FFMPEG ignores --enable-pic option #44134

Open
orange-cpp opened this issue Mar 3, 2025 · 6 comments
Open

FFMPEG ignores --enable-pic option #44134

orange-cpp opened this issue Mar 3, 2025 · 6 comments
Assignees
Labels
requires:repro The issue is not currently repro-able

Comments

@orange-cpp
Copy link

When i build ffmpeg on arch linux using vcpkg install ffmpeg:x64-linux i got error from linker:

libswscale.a(swscale.o): warning: relocation againstff_M24B' in read-only section .text' /usr/bin/ld: ibavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol ff_pw_9' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
`

But in vcpkg output --enable-pic is set by default.

How can i make FFMPEG link normaly in my .so program?

PS: I need to static linking of FFMPEG.

@WangWeiLin-MV WangWeiLin-MV added the requires:repro The issue is not currently repro-able label Mar 4, 2025
@WangWeiLin-MV
Copy link
Contributor

Using the latest version of vcpkg for local installation does not reproduce the issue.

Would you please provide a repro step or commands? I've tried vcpkg install ffmpeg.

@orange-cpp
Copy link
Author

orange-cpp commented Mar 4, 2025

Using the latest version of vcpkg for local installation does not reproduce the issue.

Would you please provide a repro step or commands? I've tried vcpkg install ffmpeg.

Did you try to link ffmpeg with your dynamic library not executable? it will fail compilation.

@orange-cpp
Copy link
Author

Using the latest version of vcpkg for local installation does not reproduce the issue.

Would you please provide a repro step or commands? I've tried vcpkg install ffmpeg.

i meant ffpeg builds but it cant be linked

@WangWeiLin-MV
Copy link
Contributor

The following usage test passes.

cmake_minimum_required(VERSION 3.25.1)
project(Test VERSION 0.1.2.3 LANGUAGES CXX)

add_executable(main c.cpp)
target_compile_features(main PRIVATE cxx_std_23)

find_package(FFMPEG REQUIRED)
target_include_directories(main PRIVATE ${FFMPEG_INCLUDE_DIRS})
target_link_directories(main PRIVATE ${FFMPEG_LIBRARY_DIRS})
target_link_libraries(main PRIVATE ${FFMPEG_LIBRARIES})
#ifdef __cplusplus
extern "C" {
#endif
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
#ifdef __cplusplus
}
#endif

#include <iostream>
int main() {

std::cout << "ffmpeg" << std::endl;
std::cout << av_version_info() << std::endl;

return 0;
}

i meant ffpeg builds but it cant be linked

Would you please provide a simple repro case?

@orange-cpp
Copy link
Author

The following usage test passes.

cmake_minimum_required(VERSION 3.25.1)
project(Test VERSION 0.1.2.3 LANGUAGES CXX)

add_executable(main c.cpp)
target_compile_features(main PRIVATE cxx_std_23)

find_package(FFMPEG REQUIRED)
target_include_directories(main PRIVATE ${FFMPEG_INCLUDE_DIRS})
target_link_directories(main PRIVATE ${FFMPEG_LIBRARY_DIRS})
target_link_libraries(main PRIVATE ${FFMPEG_LIBRARIES})

#ifdef __cplusplus
extern "C" {
#endif
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
#ifdef __cplusplus
}
#endif

#include
int main() {

std::cout << "ffmpeg" << std::endl;
std::cout << av_version_info() << std::endl;

return 0;
}

i meant ffpeg builds but it cant be linked

Would you please provide a simple repro case?

no, use add_library(main MODULE c.cpp) and it will fail

@orange-cpp
Copy link
Author

#ifdef __cplusplus
extern "C" {
#endif
#include "libavcodec/avcodec.h"
#include "libavutil/avutil.h"
#ifdef __cplusplus
}
#endif



#include <iostream>


__attribute__ ((visibility ("default"))) int main() {

    avcodec_find_encoder(AV_CODEC_ID_H264);
    std::cout << "ffmpeg" << std::endl;
    std::cout << av_version_info() << std::endl;

    return 0;
}
project(Test VERSION 0.1.2.3 LANGUAGES CXX)

add_library(main MODULE library.cpp)
target_compile_features(main PRIVATE cxx_std_23)

find_package(FFMPEG REQUIRED)
target_include_directories(main PRIVATE ${FFMPEG_INCLUDE_DIRS})
target_link_directories(main PRIVATE ${FFMPEG_LIBRARY_DIRS})
target_link_libraries(main PRIVATE ${FFMPEG_LIBRARIES})

Build log:

cmake --build /home/vlad/CLionProjects/untitled1/cmake-build/build/linux-release --target main -j 6
[2/2] Linking CXX shared module libmain.so
FAILED: libmain.so 
: && /usr/bin/g++ -fPIC -O3 -DNDEBUG  -Wl,--dependency-file=CMakeFiles/main.dir/link.d -shared  -o libmain.so CMakeFiles/main.dir/library.cpp.o -L/home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib   -L/home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/debug/lib -Wl,-rpath,/home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib:/home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/debug/lib  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavdevice.a  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavfilter.a  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavformat.a  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavcodec.a  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libswresample.a  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libswscale.a  /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavutil.a  -pthread  -lm  -latomic && :
/usr/bin/ld: /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavcodec.a(h264_intrapred_10bit.o): warning: relocation against `ff_pw_512' in read-only section `.text'
/usr/bin/ld: /home/vlad/CLionProjects/untitled1/extlibs/vcpkg/installed/x64-linux/lib/libavcodec.a(vc1dsp_mmx.o): relocation R_X86_64_PC32 against symbol `ff_pw_9' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.

Repo with this sample: https://github.com/orange-cpp/ffpmeg-fpic-error-cmake

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:repro The issue is not currently repro-able
Projects
None yet
Development

No branches or pull requests

2 participants