我正在编写一个应用程序,其中包含2个内部库,并依赖于2个以上的外部库(ffmpeg和opencv)。我还使用cmake生成unix生成文件。问题是,当我试图构建源代码时,它会编译,但根本不会与ffmpeg链接,链接器会给出下一个输出:
../../Decoder/libDecoder.a(ConverterAVFrameToRGB.cpp.o): In function `FaceVideo::ConverterAVFrameToRGB::to_rgb_conversion(std::vector<AVFrame*, std::allocator<AVFrame*> >&, int, int, int)':
ConverterAVFrameToRGB.cpp:(.text+0x990): undefined reference to `av_frame_free'
../../Decoder/libDecoder.a(FfmpegDecoder.cpp.o): In function `FaceVideo::FfmpegDecoder::destroy()':
FfmpegDecoder.cpp:(.text+0xa30): undefined reference to `av_frame_free'
../../Decoder/libDecoder.a(FfmpegDecoder.cpp.o): In function `FaceVideo::FfmpegDecoder::decode_next_chunk(int)':
FfmpegDecoder.cpp:(.text+0xb6b): undefined reference to `av_frame_clone'
FfmpegDecoder.cpp:(.text+0xc13): undefined reference to `av_frame_free'
../../Decoder/libDecoder.a(FfmpegEncoder.cpp.o): In function `FaceVideo::FfmpegEncoder::destroy()':
FfmpegEncoder.cpp:(.text+0x132): undefined reference to `avcodec_free_frame'
../../Decoder/libDecoder.a(FfmpegEncoder.cpp.o): In function `FaceVideo::FfmpegEncoder::encode()':
FfmpegEncoder.cpp:(.text+0x4c4): undefined reference to `avcodec_encode_video2'
FfmpegEncoder.cpp:(.text+0x592): undefined reference to `avcodec_encode_video2'
../../Decoder/libDecoder.a(FrameSaver.cpp.o): In function `FaceVideo::FrameSaver::saver(std::vector<AVFrame*, std::allocator<AVFrame*> >&, int, int, int)':
FrameSaver.cpp:(.text+0x869): undefined reference to `av_frame_free'
collect2: ld returned 1 exit status
这是我不想看到的。
有三个cmake文件:两个用于内部库(使用
add_library(Decoder ${SOURCES_DECODER})
and
add_library(Detector ${SOURCES_DETECTOR})
其中一个用于主可执行文件(使用
add_executable(Tool ${SOURCES_TOOL})
and
target_link_libraries (Tool Decoder avutil avcodec swscale avformat Detector ${OpenCV_LIBS})
在里面)。
据我从cmake手册和示例中了解,这应该会使链接器将这些库链接在一起,但不会产生任何效果。
我尝试了很多事情,比如:
1)添加
link_directories()
和指向库的路径(对于我来说是/usr/lib/x86_64-linux-gnu/for me),只要可能,什么都不会改变。2)分别链接每个库,我是说我尝试在内部库cmake文件中执行类似的操作:
target_link_libraries (Decoder avutil avcodec swscale avformat)
。然后将库链接到我的工具cmake文件:target_link_libraries (Tool Decoder Detector)
。3)编辑输出生成文件。
4)编译简单的一个文件应用程序来测试我是否能做到。我可以。
g++ -lavcodec -o out mysource.cpp
工作正常。5)手动编译ffmpeg并安装。
事实上我真的不知道该怎么办。我不知道。我非常感谢你的每一个回答。
升级1:
设置cmake_verbose_makefile时的输出
啊!
/usr/bin/c++-march=x86-64-wall-fpic-pthread-std=c++0x-d\u stdc\u常量宏-march=x86-64-fpic cmakefiles/facedetectortool.dir/home/anton/programming/facevideo/branches/stream\prototype/src/tools/facedetectortool/facedetector.cpp.o-o facedetectortool-rdynamic../../detector/libdetector.a../decoder/libdecoder.a-lavutil-Lavcodec-lswscale-lavformat/usr/local/lib/libopencv/libopencv/libopencv/libopencv/lib/libopencv/lib/opencv/v/v.2.4.7/usr/local/lib/libopencv/usr/local/libopencv/libopencv/libopencv/libopencv/libopencv/supperres.so.2.4.7/usr/local/libopencv/libopencv/opencv/supperres.2.4.4.7/usr/local/libopencv/libopencv/libopencv/lib/libopencv/lib/libopencv/us2.4./libopencv_ocl.so.2.4.7版本/usr/local/lib/libopencv/libopencv/libopencv/libopencv/libopencv-unfree.so.2.4.7/usr/local/lib/libopencv/libopencv-ml.so.2.4.7/usr/local/lib/libopencv/libopencv/libopencv-lega遗留.so.2.4.7/usr/local/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv.2.4.4.4.7/usr/local/libopencv/lib/libopencv/libopencv/lib/_gpu.so.2.4.7/usr/local/lib/libopencv_flann.so.2.4.7版本/usr/local/lib/libopencv/libopencv-features2d.so.2.4.4.7/usr/local/lib/libopencv/libopencv-contrib.so.2.4.7/usr/local/lib/libopencv/libopencv/libopencv/libopencv/libopencv-calib3.so.2.4.7-ldl-lm-lpthread-lrt/usr/local/lib/lib/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv/libopencv-ocl.so.2.4.4.4.7./usr/local/lib/libopencv_gpu.so.2.4.7/usr/local/lib/libopencv_photo.so.2.4.7版本/usr/local/lib/libopencv/libopencv/libopencv.2.4.7/usr/local/lib/libopencv.2.4.7/usr/local/lib/libopencv/libopencv.2.4.7/usr/local/libopencv/libopencv.2.4.7/usr/local/libopencv/libopencv/libopencv/libopencv.2.4.7/usr/local/lib/lib/libopencv/libopencv/libopencv.2.4.4.7/usr/local/libopencv/libopencv/libopencv.2.4.4.7/usr/local/libopencv/_highgui.so.2.4.7/usr/local/lib/libopencv_imgproc.so.2.4.7版本/usr/local/lib/libopencv_flann.so.2.4.7/usr/local/lib/libopencv_core.so.2.4.7-wl,-rpath,/usr/local/lib
上浮2
cmake示例看起来就是这样。
cmake_minimum_required (VERSION 2.8)
project (Decoder)
include(../CMakeInit.cmake)
include_directories(${FFMPEG_INCLUDE_DIR})
include_directories(${Stream_Facevideo_SOURCE_DIR}/../src/kernel/decoder/)
include_directories(${Stream_Facevideo_SOURCE_DIR}/../src/kernel/stuff/)
set(SOURCES_VIDEODECODER
*sources*
)
if(WINDOWS)
set(SOURCES_VIDEODECODER ${SOURCES_VIDEODECODER}
*headers*
)
endif(WINDOWS)
set (SOURCES_DECODER
${SOURCES_VIDEODECODER}
)
add_library(Decoder ${SOURCES_DECODER})
link_directories("/usr/lib/x86_64-linux-gnu/")
target_link_libraries(Decoder swscale avformat avcodec avutil)
最佳答案
似乎这个解决方案应该有效:Findavutil.cmake&CMakeLists.txt