这不是关于 C++,而是更多关于特定编译 avcodec 和 avformat 的内容,因为它们在FFmpeg中使用。我正在尝试第一次编译ffmpeg项目代码。所有链接都已解决,程序错误我们。
我正在编写我的第一个程序 - 尝试在我的 C++ 代码中使用 avformat 库。此行的链接器错误:
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/sasha/CLionProjects/ffmpeg-01 --target all -- -j 12
Scanning dependencies of target docs
[ 5%] Generating HTML documentation
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/input.c.o
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/init.c.o
[ 20%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/context.c.o
[ 30%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/vulkan.c.o
[ 30%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/monitor.c.o
[ 35%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_init.m.o
[ 45%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_joystick.m.o
[ 45%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/window.c.o
[ 50%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_monitor.m.o
[ 60%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_window.m.o
[ 60%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/cocoa_time.c.o
[ 60%] Built target docs
[ 65%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/posix_thread.c.o
[ 70%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/nsgl_context.m.o
[ 75%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/egl_context.c.o
[ 80%] Building C object lib/glfw/src/CMakeFiles/glfw.dir/osmesa_context.c.o
[ 85%] Linking C static library libglfw3.a
[ 85%] Built target glfw
[ 95%] Building CXX object CMakeFiles/ffmpeg_01.dir/src/main.cpp.o
[ 95%] Building CXX object CMakeFiles/ffmpeg_01.dir/src/load_frame.cpp.o
[100%] Linking CXX executable ffmpeg_01
clang: error: no such file or directory: 'VideoToolbox'
clang: error: no such file or directory: 'CoreFoundation'
clang: error: no such file or directory: 'CoreMedia'
clang: error: no such file or directory: 'CoreVideo'
clang: error: no such file or directory: 'CoreServices'
clang: error: no such file or directory: 'OpenGL'
clang: error: no such file or directory: 'CoreImage'
clang: error: no such file or directory: 'AppKit'
clang: error: no such file or directory: 'Foundation'
clang: error: no such file or directory: 'CoreAudio'
clang: error: no such file or directory: 'AVFoundation'
clang: error: no such file or directory: 'CoreGraphics'
make[2]: *** [ffmpeg_01] Error 1
make[1]: *** [CMakeFiles/ffmpeg_01.dir/all] Error 2
make: *** [all] Error 2
这是我的* libavcodec.pc文件的内容,它有一个冲突条目:它列出了clang 找不到的所有项目,我不知道它们是否以某种方式链接。我发现一个来源指出,如果我有其他 ffmpeg 分支,则会出现类似的错误,但我没有。
prefix=/usr/local
exec_prefix=${prefix}
libdir=/usr/local/lib
includedir=/usr/local/include
Name: libavcodec
Description: FFmpeg codec library
Version: 58.108.100
Requires: libswresample >= 3.8.100, libavutil >= 56.60.100
Requires.private:
Conflicts:
Libs: -L${libdir} -lavcodec -liconv -lm -llzma -lz -framework AudioToolbox -L/usr/local/Cellar/x264/r3011/lib -lx264 -pthread -framework VideoToolbox -framework CoreFoundation -framework CoreMedia -framework CoreVideo -framework CoreServices
Libs.private:
Cflags: -I${includedir}
我没有cmakefile的经验,如果需要我可以在这里粘贴。非常感谢任何帮助,因为过去几天我都被困住了。
我有两个 CMakeLists:
cmake_minimum_required(VERSION 3.17)
project(ffmpeg_01)
set(CMAKE_CXX_STANDARD 14)
add_subdirectory(lib/glfw)
add_subdirectory(lib/FFmpeg)
add_definitions(-DGL_SILENCE_DEPRECIATION)
if(APPLE)
list(APPEND EXTRA_LIBS
"-framework OpenGL"
)
elseif(LINUX)
list(APPEND EXTRA_LIBS
"-lGL -lGLU -lX11")
endif()
add_executable(ffmpeg_01 src/main.cpp src/load_frame.cpp)
target_link_libraries(ffmpeg_01 FFmpeg glfw ${EXTRA_LIBS})
以及FFmpeg子目录下FFmpeg的接口:
cmake_minimum_required(VERSION 3.17)
project(FFMPEG)
find_package(PkgConfig REQUIRED)
pkg_check_modules(AVCODEC REQUIRED IMPORTED_TARGET libavcodec)
pkg_check_modules(AVFORMAT REQUIRED IMPORTED_TARGET libavformat)
pkg_check_modules(AVFILTER REQUIRED IMPORTED_TARGET libavfilter)
pkg_check_modules(AVDEVICE REQUIRED IMPORTED_TARGET libavdevice)
pkg_check_modules(AVUTIL REQUIRED IMPORTED_TARGET libavutil)
pkg_check_modules(SWRESAMPLE REQUIRED IMPORTED_TARGET libswresample)
pkg_check_modules(SWSCALE REQUIRED IMPORTED_TARGET libswscale)
add_library(FFmpeg INTERFACE IMPORTED GLOBAL)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVCODEC)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVFORMAT)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVFILTER)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVDEVICE)
target_link_libraries(FFmpeg INTERFACE PkgConfig::AVUTIL)
target_link_libraries(FFmpeg INTERFACE PkgConfig::SWRESAMPLE)
target_link_libraries(FFmpeg INTERFACE PkgConfig::SWSCALE)
我还尝试在 target_link_libraries 下添加以下块,但编译结果没有区别:
target_link_options(FFmpeg INTERFACE
${AVCODEC_LDFLAGS_OTHERS}
${AVFORMAT_LDFLAGS_OTHERS}
${AVFILTER_LDFLAGS_OTHERS}
${AVDEVICE_LDFLAGS_OTHERS}
${AVUTIL_LDFLAGS_OTHERS}
${SWRESAMPLE_LDFLAGS_OTHERS}
${SWSCALE_LDFLAGS_OTHERS}
)