作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 ubuntu(vagrant) 中构建一个使用 ffmpeg 库(libavcodec.a、libavformat.a、libavutil.a)的共享对象文件。我首先使用标准配置选项从 trac.ffmpeg 构建 ffmpeg 和库.但是动态链接存在一些问题,我稍微修改了配置选项以添加 --enable-shared
和 -fPIC
选项。
However when I build my application I get
/usr/bin/ld: /root/ffmpeg_build/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
我在配置中使用了以下选项来构建 ffmpeg
PATH="$HOME/bin:$PATH" PKG_CONFIG_PATH="$HOME/ffmpeg_build/lib/pkgconfig:$PKG_CONFIG_PATH" ./configure \
--prefix="$HOME/ffmpeg_build" \
--pkg-config-flags="--static" \
--extra-cflags="-I$HOME/ffmpeg_build/include -fPIC" \
--extra-ldflags="-L$HOME/ffmpeg_build/lib -Wl,-Bsymbolic" \
--extra-libs="-lpthread -lm" \
--bindir="$HOME/bin" \
--enable-gpl \
--enable-libass \
--enable-libfdk-aac \
--enable-libfreetype \
--enable-libmp3lame \
--enable-libopus \
--enable-libvorbis \
--enable-libvpx \
--enable-libx264 \
--enable-libx265 \
--enable-nonfree \
--enable-pic \
--enable-shared
构建在我的 MAC 上运行良好。
以下是我构建应用程序的cmake文件
cmake_minimum_required(VERSION 3.5)
project(extractor C)
set(CMAKE_C_STANDARD 99)
set(EXECUTABLE_NAME "extractor")
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules)
set(EXTRACTOR_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(target_dir "bin")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -std=99")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
# set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic")
add_library(${EXECUTABLE_NAME} SHARED src/frame_extractor.c)
include_directories(".")
find_package(FFmpeg REQUIRED)
if (FFMPEG_FOUND)
message("Found FFMPEG/LibAV libraries ${FFMPEG_LIBRARIES}")
message("include dirs ${FFMPEG_INCLUDE_DIR}")
include_directories(${FFMPEG_INCLUDE_DIR})
target_link_libraries(${EXECUTABLE_NAME} ${FFMPEG_LIBRARIES})
else (FFMPEG_FOUND)
message("cant find libavcodec, libavformat or libavutil. add them manually!!")
endif (FFMPEG_FOUND)
target_link_libraries(${EXECUTABLE_NAME} ${FFMPEG_LIBRARIES})
# target_link_libraries (${EXECUTABLE_NAME} "-lm")
# target_link_libraries (${EXECUTABLE_NAME} "-lavcodec")
if(APPLE)
#target_link_libraries(${EXECUTABLE_NAME} "-framework CoreServices")
#target_link_libraries(${EXECUTABLE_NAME} "-framework CoreFoundation")
#target_link_libraries(${EXECUTABLE_NAME} "-framework AudioToolbox")
#target_link_libraries(${EXECUTABLE_NAME} "-framework VideoToolbox")
#target_link_libraries(${EXECUTABLE_NAME} "-framework CoreAudio")
#target_link_libraries(${EXECUTABLE_NAME} "-framework CoreMedia")
#target_link_libraries(${EXECUTABLE_NAME} "-framework CoreVideo")
#target_link_libraries(${EXECUTABLE_NAME} "-framework AVFoundation")
#target_link_libraries(${EXECUTABLE_NAME} "-framework Security")
#target_link_libraries(${EXECUTABLE_NAME} /usr/lib/libbz2.1.0.dylib)
#target_link_libraries(${EXECUTABLE_NAME} /usr/lib/libz.1.dylib)
#target_link_libraries(${EXECUTABLE_NAME} /usr/lib/libiconv.dylib)
#target_link_libraries(${EXECUTABLE_NAME} /usr/lib/liblzma.dylib)
#target_link_libraries(${EXECUTABLE_NAME} /usr/local/lib/libswresample.a)
#target_link_libraries(${EXECUTABLE_NAME} /usr/local/Cellar/fdk-aac/0.1.6/lib/libfdk-aac.dylib)
#target_link_libraries(${EXECUTABLE_NAME} /usr/local/lib/libx264.dylib)
endif(APPLE)
# Add python dependencies -
# ERROR - It picks up the default version from the machine which is 2.7.10
find_package( PythonInterp 2.7 REQUIRED)
find_package(PythonLibs 2.7 REQUIRED)
message("GURU - python include dirs = ${PYTHON_INCLUDE_DIRS}")
message("GURU - python include dirs = ${PYTHON_LIBRARIES}")
include_directories(${PYTHON_INCLUDE_DIRS})
target_link_libraries(${EXECUTABLE_NAME} ${PYTHON_LIBRARIES})
# Apple creates annoying dylib extension for shared libraries
if(APPLE)
SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
endif(APPLE)
set(CMAKE_SHARED_LIBRARY_PREFIX "")
非常感谢您帮助解决这个问题。
最佳答案
我遇到了同样的问题。有趣的是,您自己的 CMakeLists.txt 为我指明了答案。
取消注释
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic")
关于gcc - libavcodec.a(vc1dsp_mmx.o) : relocation R_X86_64_PC32 against symbol `ff_pw_9' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51529926/
我是一名优秀的程序员,十分优秀!