【发布时间】:2019-11-29 18:46:24
【问题描述】:
我正在尝试在 C++ 项目中使用来自 ffmpeg 的 libavformat。我已经使用自制软件安装了 ffmpeg。
我的 CMakeLists.txt :
cmake_minimum_required(VERSION 3.14)
project(av_test)
set(CMAKE_CXX_STANDARD 11)
INCLUDE_DIRECTORIES(/usr/local/Cellar/ffmpeg/4.2.1_2/include)
LINK_DIRECTORIES(/usr/local/Cellar/ffmpeg/4.2.1_2/lib)
add_executable(av_test main.cpp)
TARGET_LINK_LIBRARIES(av_test libavformat)
运行 cmake 时出现此错误:
ld: library not found for -llibavformat
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [av_test] Error 1
make[2]: *** [CMakeFiles/av_test.dir/all] Error 2
make[1]: *** [CMakeFiles/av_test.dir/rule] Error 2
make: *** [av_test] Error 2
快速find libavformat* 进入 /usr/local/Cellar/ffmpeg/4.2.1_2/lib 返回:
libavformat.58.29.100.dylib
libavformat.58.dylib
libavformat.a
libavformat.dylib
在 /usr/local/Cellar/ffmpeg/4.2.1_2/include/libavformat 中还有 avformat.h
我的 main.cpp:
#include <libavformat/avformat.h>
int main() {
AVFormatContext *pFormatContext;
return 0;
}
我在 mac os 10.14 上运行 cmake 版本 3.15.5 ,ffmpeg 版本 4.2.1
【问题讨论】:
-
尝试编写 TARGET_LINK_LIBRARIES(av_test avformat) 或尝试编写 TARGET_LINK_LIBRARIES(av_test -lavformat)
-
@Saisai3396 谢谢,这行得通!能否请您写一个答案,以便我将其标记为解决方案?
-
很高兴为您提供帮助! :)
标签: c++ macos ffmpeg cmake libavformat