1、编译出错,如下图:
2、可是我的cmakelists.txt,明明链接了啊
# CMake 最低版本号要求
cmake_minimum_required (VERSION 3.5)
# 项目信息
project (ffmdecoder-Demo1)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -fpermissive")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall -fpermissive")
set(root_path /workspace/depends)
#dependencies
# set(ENV{PKG_CONFIG_PATH} "${root_path}/simple-x86-omx-ffmpeg5.0/lib/pkgconfig")
set(ENV{PKG_CONFIG_PATH} "${root_path}/simple-x86-omx-ffmpeg5.0/lib/pkgconfig")
find_package(PkgConfig)
pkg_check_modules(FFMPEG REQUIRED libavformat libavutil libavcodec)
message(STATUS "=== FFMPEG_LIBRARIES: ${FFMPEG_LIBRARIES}")
message(STATUS "=== FFMPEG_INCLUDE_DIRS: ${FFMPEG_INCLUDE_DIRS}")
message(STATUS "=== FFMPEG_LIBRARY_DIRS: ${FFMPEG_LIBRARY_DIRS}")
message(STATUS "=== FFMPEG_CFLAGS: ${FFMPEG_CFLAGS}")
FOREACH(flag ${FFMPEG_CFLAGS})
SET(EXTRA_CFLGAS "${EXTRA_CFLGAS} ${flag}")
ENDFOREACH(flag)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLGAS}")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLGAS}")
include_directories(${FFMPEG_INCLUDE_DIRS} )
link_directories(${FFMPEG_LIBRARY_DIRS})
set(SOURCES main.cpp)
# 指定生成目标
add_executable(FFm_Dec ${SOURCES})
target_link_libraries(FFm_Dec ${FFMPEG_LIBRARIES})
3、继续排查错误,在看build命令的时候发现:
[build] : && /usr/bin/g++ -I/workspace/depends/simple-x86-omx-ffmpeg5.0/include -O0 -Wall -g -fpermissive CMakeFiles/FFm_Dec.dir/main.cpp.o -o bin/FFm_Dec -L/workspace/depends/simple-x86-omx-ffmpeg5.0/lib -Wl,-rpath,/workspace/depends/simple-x86-omx-ffmpeg5.0/lib -lavformat -lavutil -lavcodec && :
这里用的是g++
4、赶快看main.cpp中头文件是不是同过这种方式:
#ifdef __cplusplus
extern "C" {
#endif
#include <libavcodec/avcodec.h>
#ifdef __cplusplus
}
#endif
发现还真不是,赶紧改为这个方式,编译就成功了