I am building a Qt application (with CMake) that will capture and analyze some network packets. Since I am using C++ all over the project, it would be convenient for me to use Pcap++ in my application rather than using lower lever C APIs provided by libs such as libpcap or winpcap.
However I find it hard to use pre-built Pcap++ libraries in my CMakeLists.txt given that no much info was provided on how such an integration would look like.
The application is supposed to be cross-platform and I started with integrating Pcap++ on windows first. So I have downloaded pre-built pcapplusplus-22.05-windows-mingw32-gcc-9.2.0. And then tried to follow instructions from Readme and apply them to my CMake file.
I post here the relevant parts of CMakeLists to show how I have attempted to do it:
set(THIRD_PARTY_LIBS "")
set(THIRD_PARTY_INCLUDES "")
# Add Pcap++ headers
list(APPEND THIRD_PARTY_INCLUDES ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/header)
# Pcap++ libs and dependencies according to their README
list(APPEND THIRD_PARTY_LIBS pthread ws2_32 iphlpapi)
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Common++.lib)
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Packet++.lib)
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Pcap++.lib)
# Add WinPcap libs
list(APPEND THIRD_PARTY_LIBS ${CMAKE_CURRENT_LIST_DIR}/WpdPack/Lib/Packet.lib ${CMAKE_CURRENT_LIST_DIR}/WpdPack/Lib/wpcap.lib)
# Add includes to project
include_directories(${THIRD_PARTY_INCLUDES})
# Add libs to project
target_link_libraries(${PROJECT_NAME} PRIVATE ${THIRD_PARTY_LIBS} Qt${QT_VERSION_MAJOR}::Core)
The relative locations are fine. Yet, when application is linking, the following error is occurring:
cmd.exe /C "cd . && C:\Qt\Tools\mingw1120_64\bin\c++.exe -g -mwindows CMakeFiles/MyProjectName.dir/MyProjectName_autogen/mocs_compilation.cpp.obj CMakeFiles/MyProjectName.dir/src/core/AppLogger.cpp.obj CMakeFiles/MyProjectName.dir/src/main.cpp.obj CMakeFiles/MyProjectName.dir/src/utils/utils.cpp.obj CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj CMakeFiles/MyProjectName.dir/res/win.rc.obj CMakeFiles/MyProjectName.dir/MyProjectName_autogen/PNK5WDWK6L/qrc_resources.cpp.obj -o MyProjectName.exe -Wl,--out-implib,libMyProjectName.dll.a -Wl,--major-image-version,0,--minor-image-version,0 -L<proj_loc>/src/core -L<proj_loc>/src/utils -L<proj_loc>/ui thirdparty/spdlog/libspdlogd.a ../../thirdparty/WpdPack/Lib/Packet.lib ../../thirdparty/WpdPack/Lib/wpcap.lib -lpthread -lws2_32 -liphlpapi ../../thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Common++.lib ../../thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Packet++.lib ../../thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/Pcap++.lib C:/Qt/6.3.1/mingw_64/lib/libQt6Network.a C:/Qt/6.3.1/mingw_64/lib/libQt6Widgets.a -lws2_32 C:/Qt/6.3.1/mingw_64/lib/libQt6Gui.a C:/Qt/6.3.1/mingw_64/lib/libQt6Core.a -lmpr -luserenv -lmingw32 C:/Qt/6.3.1/mingw_64/lib/libQt6EntryPoint.a -lshell32 -ld3d11 -ldxgi -ldxguid -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj:<proj_loc>/thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/header/pcappp/PcapLiveDeviceList.h:47: undefined reference to `pcpp::PcapLiveDeviceList::~PcapLiveDeviceList()'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj: in function `MainWindow::on_pushButton_StartRecording_clicked()':
<proj_loc>/ui/mainwindow.cpp:36: undefined reference to `pcpp::PcapLiveDeviceList::getPcapLiveDeviceByIp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const'
C:/Qt/Tools/mingw1120_64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/MyProjectName.dir/ui/mainwindow.cpp.obj: in function `pcpp::PcapLiveDeviceList::getInstance()':
<proj_loc>/thirdparty/pcapplusplus-22.05-windows-mingw32-gcc-9.2.0/header/pcappp/PcapLiveDeviceList.h:47: undefined reference to `pcpp::PcapLiveDeviceList::PcapLiveDeviceList()'
collect2.exe: error: ld returned 1 exit status
In my application I am executing this simple function to get a network adapter by it's IP address:
this->dev = = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDeviceByIp("1.2.3.4")
Seeing "undefined reference to" makes me think that my libs were not properly included. How do I properly do it?
Later edit: It seems my application is 64bit but the libraries are 32bit compiled. This is probably my issue. However I am wondering why no warnings are visible to indicate this
On their website it is clearly stated that they don't support MinGW 64-bit compilation:
"Please notice that x64 compilation is not supported (and will not work) on either MinGW32 nor MinGW-w64!"
Therefore there is no way to link it within my 64bit application that uses MinGW.
Related
I can already cross-compile some simple applications using x86_64-w64-mingw32-g++. However, I cannot find out how to find libraries for my project (in my case I need to use SDL2 and SDL2_image). I know how to install these libraries already (sudo apt install libsdl2-dev libsdl2-image-dev), but apt search does not show any libraries for x86_64-w640mingw32-g++.
Here are the links I've looked at:
https://arrayfire.com/cross-compile-to-windows-from-linux/
https://stackoverflow.com/questions/2033997/how-to-compile-for-windows-on-linux-with-gcc-g
Is there a way to use precompiled libraries, or do I need to add the source code in my project?
Update: I followed the instructions advised by Laurent Jospin, and can compile a "Hello World" program that works with Windows (I sent it to a friend to test). However, I cannot compile my program that uses SDL.
Terminal output:
$ /opt/mxe/usr/bin/x86_64-w64-mingw32.shared-g++ -O3 main.o Game.o TextureManager2D.o Map.o Entity.o Player.o -mwindows -lSDL2 -lSDL2_image -o ../../../endeavour-client.exe
/opt/mxe/usr/lib/gcc/x86_64-w64-mingw32.shared/5.5.0/../../../../x86_64-w64-mingw32.shared/lib/../lib/libmingw32.a(lib64_libmingw32_a-crt0_c.o): In function `main':
/opt/mxe/tmp-gcc-x86_64-w64-mingw32.shared/gcc-5.5.0.build_.crt/../gcc-5.5.0.build_/mingw-w64-v8.0.0/mingw-w64-crt/crt/crt0_c.c:18: undefined reference to `WinMain'
collect2: error: ld returned 1 exit status
$
Changing -mwindows to -municode, -d UNICODE, -Wl,-subsystem,windows, or removing it all do not work.
What you are looking for is the M Cross Environnement: https://mxe.cc/
It is a set of makefiles able to download and cross compile a selection of popular libraries for windows on linux. By default it builds static libraries, such that you ends up with .a libraries that get merged into the final .exe, meaning you don't have to worry about shipping the dlls with your app. But if you prefer a modular structure, it can also builds some dlls.
The list of libraries they do provide is quite impressive. If a library is missing on the other hand you can still install it by copying the corresponding header files and dlls. In some specific situation you might have to cross-compile one of your dependency (I had to do that for an app using ruby scripting. The official windows build of ruby is somehow incompatible with certain libraries built with mingw. But this is rather exceptional).
The correct command is:
$ /opt/mxe/usr/bin/x86_64-w64-mingw32.shared-g++ -O3 main.o Game.o TextureManager2D.o Map.o Entity.o Player.o -mwindows -lmingw32 -lSDl2main -lSDL2 -lSDL2_image -o ../../../endeavour-client.exe
Edit: Note that having -lmingw32 -lSDL2main -lSDL2 -lSDL2_image in that exact order is vital.
I, being the absolute idiot that I am, forgot to include the -lmingw32 AND -lSDL2main flags in the command, which is why there is the issue with WinMain not being found. When using MinGW-w64 as the cross compiler, the -lmingw32 library has to be included. And of course, SDL requires the -lSDl2main flag when building for windows (but interestingly enough, not on Linux). Here are the links I used. (I had an uncommon insight in replacing -lSDLmain with -lSDL2main, as the links are pretty old.)
MinGW Starter Guide
Code::Blocks Forums
SO: Undefined Reference to WinMain
I am trying to create an executable that uses code from both static libraries and a shared library:
The static libs are several boost .a , pthread and libbus.a. The shared lib is a libwrap.so.
Note that the libwrap , uses code from libbus and libbus uses code from pthread. Finally, the executable uses code from libwrap and from boost.
Since the order of libraries included in the linker matters I am trying to find the "winning" sequence.
The linking stage is the following (pasted in multiple lines for convenience):
$ /usr/bin/c++
-Wall -Wextra
-fPIC
-fvisibility=hidden -fno-strict-aliasing -Wno-long-long
-m64
-rdynamic
-D_UNICODE -DUNICODE
CMakeFiles/Wrapper_Test.dir/test.cpp.o
/usr/local/lib/libboost_log.a
/usr/local/lib/libboost_system.a
/usr/local/lib/libboost_filesystem.a
/usr/local/lib/libboost_date_time.a
/usr/local/lib/libboost_thread.a
/usr/local/lib/libboost_log_setup.a
/usr/local/lib/libboost_chrono.a
-pthread
/home/nass/dev/Data_Parser/trunk/external/lib/linux64_gcc_release/libbus.a
-L/home/nass/dev/Data_Parser_build/lib #this is where the libwrap.so is located
-Wl,-rpath,/home/nass/dev/Data_Parser_build/lib
-lwrap #the shared lib
-o ../../../bin/Wrapper_Test
The link error is
CMakeFiles/Wrapper_Test.dir/test.cpp.o: In function `main':
test.cpp:(.text+0x2e): undefined reference to `wrapperNamespace::GetWrapper()'
collect2: error: ld returned 1 exit status
The GetWrapper() is located in libwrap.so of course, and I can verify it is a symbol that can be found in there:
$ nm -Ca ../../../lib/libwrap.so | grep GetWrapper
00000000000423d6 t wrapperNamespace::GetWrapper()
However, the linker cannot find it. what am I doing wrong here?
EDIT:
The linking command above is generated by the following CMakeLists.txt file:
set(TARGET_NAME Wrapper_Test)
#set(CMAKE_BINARY_DIR ${CMAKE_SOURCE_DIR}/bin)
#set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
#set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
# INCLUDE INTERNAL FOLDER
include_directories(${CMAKE_SOURCE_DIR}/include/Wrapper)
add_executable(${TARGET_NAME} test.cpp)
add_boost_lib(${TARGET_NAME} log system filesystem date_time thread log_setup chrono)
setup_libbus(${TARGET_NAME}) #the libbus.a
target_link_libraries(${TARGET_NAME} -L../../../lib -lwrap)
set_property(TARGET ${TARGET_NAME} PROPERTY FOLDER test)
I would start by looking at the cmake file which generates these lines.
It should be simple to add shared libaries to your path, for example:
find_library(
LIBWrapper
NAMES wrap
PATHS /home/nass/dev/Data_Parser_build/lib
)
And then link them to your test file, for example
add_executable(test src/test.cpp)
target_link_libraries(test ${LIBWrapper})
Similar should work for static libraries. This has the advantage that you don't have to deal with all the compiler/platform specific details which CMake supposedly handles for you, and which can be fairly complex & obscure.
If your library is generated dynamically, i.e. before cmake configuration time, you could just pass the appropriate linking flags to target_link_libraries:
target_link_libraries(test -L/home/nass/dev/Data_Parser_build/lib -lwrap)
I have used this suggestion in a few projects (e.g. https://github.com/caskorg/cask/blob/master/CMakeLists.txt) which dynamically generate the library, then link against it. If this doesn't work I suspect something else is wrong.
You should use -Wl,-Bstatic in front of static libs and -Wl,-Bdynamic for the dynamic ones. You also need to use -l for libraries and -L for library paths.
Something like:
$ /usr/bin/c++ test.cpp.o \
-L/usr/local/lib \
-Wl,-Bstatic \
-lboost_log \
-lsystem \
-L/home/nass/dev/Data_Parser_build/lib \
-Wl-Bdynamic \
-Wl,-rpath,/home/nass/dev/Data_Parser_build/lib \
-lwrap \
-o ../../../bin/Wrapper_Test
looks better. Many things depend on the version of your compiler/linker/OS.
There seems to be a bunch of similar questions to this one but they all seem to have answered that aren't related to what I'm doing.
I've been working on a C++ project using Ogre3D for over a year and I'm currently trying to add support for playing videos. I found a suitable library that uses ogre and ffmpeg to play the videos which I'm now trying to incorporate into our build system. Project uses mingw and cmake.
I've managed to compile the video library (https://github.com/scrawl/ogre-ffmpeg-videoplayer) and I managed to link it just fine with the my project.
The problem arises during linking of the main project, it complains about undefined references to basic ogre functions that we're working fine before. It points to lines of code in the new video library where the failing reference occurs.
The video library relies on ogre and ffmpeg, initially i got undefined references to ffmpeg functions but after managing to link the ffmpeg libraries with my main project those errors went away, so I don't understand the current undefined ogre references.
One thing that might be of note is that when the video library is compiling, the g++ commands does not reference ogre or ffmpeg even though the cmake files are calling target_link_libraries on them. This is a bit strange to me, but again probably just a lack of linking understanding on my part since it compiles fine.
Here's the full build log with the main linking error: http://pastebin.com/X6Lbccag
the offending lines from there:
C:\mingw\bin\g++.exe -std=c++0x -msse2 -Wno-unused-function -g -Wl,--whole-archive CMakeFiles\RunTests.dir/objects.a -Wl,--no-whole-archive -o RunTests.exe -Wl,--out-implib,libRunTests.dll.a -Wl,--major-image-version,0,--minor-image-version,0 libThrive.a contrib\googletest\libgtest_main.a C:\mingw\install\lib\libboost_thread-mt.dll C:\mingw\install\lib\libboost_date_time-mt.dll C:\mingw\install\lib\libboost_system-mt.dll C:\mingw\install\lib\libboost_chrono-mt.dll C:\mingw\install\lib\libboost_filesystem-mt.dll C:\mingw\OgreSDK\lib\Debug\libOgreMain_d.dll.a C:\mingw\install\lib\libboost_thread-mt.dll C:\mingw\install\lib\libboost_date_time-mt.dll C:\mingw\install\lib\libboost_system-mt.dll C:\mingw\install\lib\libboost_chrono-mt.dll C:\mingw\install\lib\libboost_filesystem-mt.dll C:\mingw\OgreSDK\lib\Debug\libOgreMain_d.dll.a C:\mingw\OgreSDK\lib\Debug\libOIS_d.dll.a C:\mingw\install\lib\libBulletDynamics_Debug.a C:\mingw\install\lib\libBulletCollision_Debug.a C:\mingw\install\lib\libLinearMath_Debug.a C:\mingw\install\lib\libBulletSoftBody_Debug.a C:\mingw\install\lib\libCEGUIBase-9999_d.dll.a C:\mingw\install\lib\libCEGUIOgreRenderer-9999_d.dll.a C:\mingw\install\lib\libtinyxml.a C:\mingw\install\lib\Debug\libogre-ffmpeg-videoplayer.a C:\mingw\install\lib\libavcodec.dll.a C:\mingw\install\lib\libavformat.dll.a C:\mingw\install\lib\libavutil.dll.a C:\mingw\install\lib\libswscale.dll.a C:\mingw\install\lib\libswresample.dll.a contrib\luabind\src\libluabind.a contrib\lua\liblua.dll.a -lm C:\mingw\install\bin\libcAudio.dll contrib\googletest\libgtest.a -lpthread -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
C:\mingw\install\lib\Debug\libogre-ffmpeg-videoplayer.a(videostate.cpp.obj): In function `ZN5Video10VideoState4initERKSs':
C:/mingw/temp/ffmpeg/ogre-ffmpeg-videoplayer-master/src/videostate.cpp:617: undefined reference to `Ogre::ResourceGroupManager::openResource(std::string const&, std::string const&, bool, Ogre::Resource*)'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[2]: *** [RunTests.exe] Error 1
mingw32-make.exe[1]: *** [CMakeFiles/RunTests.dir/all] Error 2
mingw32-make.exe: *** [all] Error 2
You'll notice that libOgreMain_d.dll.a is linked in the failing command which is what contains the referenced Ogre::ResourceGroupManager::openResource function (i confirmed this by finding the function in the semi-scrambled libOgreMain_d.dll.a). The cmakelists.txt: http://pastebin.com/LVsJtxny
Here's the compilation log from the video library: http://pastebin.com/k3jLiL09
and it's cmakelists.txt: https://github.com/scrawl/ogre-ffmpeg-videoplayer/blob/master/CMakeLists.txt
My first thought that perhaps the problem was in the video library compilation not linking to ogre since the g++ commands don't mention ogre, but the cmakelists.txt seems to be fine (I confirms that it finds ogre and that ogre is included in the target_link_libraries)
My second thought we're that perhaps they link to different versions of ogre but that can't be as they both find the same ogre installation and same ogre libraries.
Is anyone able to spot what I might be doing wrong and what I could try to fix the issue?
Thanks!
I managed to solve it.
Reordering the list of libraries to link in the target_link_libraries command such that the new video library was included before ogre seems to have solved my problem.
I'll accept my own answer in 6 hours
I'm writing an application containig 2 internal libraries and depends on more 2 external libraries (ffmpeg and opencv). I'm also using CMake to produce UNIX makefiles. And the problem is when i'm trying to build sources, it compiles but don't link with ffmpeg at all and the next output the linker gives:
../../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
That's excatly what i don't want to see.
There are three Cmake files: two for internal libraries (use
add_library(Decoder ${SOURCES_DECODER})
and
add_library(Detector ${SOURCES_DETECTOR})
in them) and one for main executable (use
add_executable(Tool ${SOURCES_TOOL})
and
target_link_libraries (Tool Decoder avutil avcodec swscale avformat Detector ${OpenCV_LIBS})
in it).
As far as i understand from CMake manuals and examples, this should make linker link this libraries together, but no effect.
I've been trying lot of things such as:
1) Adding link_directories() with path to libraries (/usr/lib/x86_64-linux-gnu/ for me) wherever it's possile, nothing changed.
2) Linking every library separately, i mean i tried do something like this in my internal libraries CMake files: target_link_libraries (Decoder avutil avcodec swscale avformat). And then link library together into my Tool CMake file: target_link_libraries (Tool Decoder Detector).
3) Editing output makefiles.
4) Compiling simple one-file application just to test whether i can do it or not. I can. g++ -lavcodec -o out mysource.cpp works perfectly.
5) Compling ffmpeg manually and installing it.
The fact is i realy don't know what should i do. I have no idea. And i would very appreciate your every answer.
UPD1:
Output when CMAKE_VERBOSE_MAKEFILE is set
!
/usr/bin/c++ -march=x86-64 -Wall -fPIC -pthread -std=c++0x -D__STDC_CONSTANT_MACROS -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_videostab.so.2.4.7 /usr/local/lib/libopencv_video.so.2.4.7 /usr/local/lib/libopencv_ts.a /usr/local/lib/libopencv_superres.so.2.4.7 /usr/local/lib/libopencv_stitching.so.2.4.7 /usr/local/lib/libopencv_photo.so.2.4.7 /usr/local/lib/libopencv_ocl.so.2.4.7 /usr/local/lib/libopencv_objdetect.so.2.4.7 /usr/local/lib/libopencv_nonfree.so.2.4.7 /usr/local/lib/libopencv_ml.so.2.4.7 /usr/local/lib/libopencv_legacy.so.2.4.7 /usr/local/lib/libopencv_imgproc.so.2.4.7 /usr/local/lib/libopencv_highgui.so.2.4.7 /usr/local/lib/libopencv_gpu.so.2.4.7 /usr/local/lib/libopencv_flann.so.2.4.7 /usr/local/lib/libopencv_features2d.so.2.4.7 /usr/local/lib/libopencv_core.so.2.4.7 /usr/local/lib/libopencv_contrib.so.2.4.7 /usr/local/lib/libopencv_calib3d.so.2.4.7 -ldl -lm -lpthread -lrt /usr/local/lib/libopencv_nonfree.so.2.4.7 /usr/local/lib/libopencv_ocl.so.2.4.7 /usr/local/lib/libopencv_gpu.so.2.4.7 /usr/local/lib/libopencv_photo.so.2.4.7 /usr/local/lib/libopencv_objdetect.so.2.4.7 /usr/local/lib/libopencv_legacy.so.2.4.7 /usr/local/lib/libopencv_video.so.2.4.7 /usr/local/lib/libopencv_ml.so.2.4.7 /usr/local/lib/libopencv_calib3d.so.2.4.7 /usr/local/lib/libopencv_features2d.so.2.4.7 /usr/local/lib/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
UPD2
Cmake example looks like that.
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)
Seems this solution should work: Findavutil.cmake & CMakeLists.txt
Your problem looks like you forget to add LINK_DIRECTORIES for ffmpeg lib.
If it's ok then try to change order of linking libs in target_link_libraries for executable or add target_link_libraries for your internal libs, that use external ones.
I'm trying to build RecastNavigation via MinGW, everything seems builds just fine except RecastDemo application.
I've done:
cmake -G"MSYS Makefiles" -DSDL_INCLUDE_DIR:PATH=/c/_libdist/x86/msys/include/SDL \
-DSDL_LIBRARY:PATH=/c/_libdist/x86/msys/lib/libSDL.a \
-DSDLMAIN_LIBRARY:PATH=/c/_libdist/x86/msys/lib/libSDLMain.a ..
then make VERBOSE=1 gives me this at the end (cut out bunch of undefines):
cd /C/_lib/blackberry/RecastNavigation/build.msys/RecastDemo && /C/app/MinGW/bin/g++.exe -O3 -DNDEBUG -mwindows -Wl,
--whole-archive CMakeFiles/RecastDemo.dir/objects.a -Wl,--no-whole-archive -o ../../RecastDemo/Bin/RecastDemo.exe -Wl,-
-out-implib,../../RecastDemo/Bin/libRecastDemo.dll.a -Wl,--major-image-version,0,--minor-image-version,0 ../DebugUtils/
libDebugUtils.a ../Detour/libDetour.a ../DetourCrowd/libDetourCrowd.a ../DetourTileCache/libDetourTileCache.a ../Recast/
libRecast.a /c/_libdist/x86/msys/lib/libSDL.a /c/_libdist/x86/msys/lib/libSDLMain.a -lglu32 -lopengl32 -lkernel32 -luser
32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32
Creating library file: ../../RecastDemo/Bin/libRecastDemo.dll.a
c:/_libdist/x86/msys/lib/libSDL.a(SDL_systimer.o): In function `SDL_StartTicks':
c:\_lib\SDL\1.2.15/./src/timer/win32/SDL_systimer.c:67: undefined reference to `timeBeginPeriod#4'
c:\_lib\SDL\1.2.15/./src/timer/win32/SDL_systimer.c:68: undefined reference to `timeGetTime#0'
c:/_libdist/x86/msys/lib/libSDL.a(SDL_systimer.o): In function `SDL_GetTicks':
...
...
...
c:/app/mingw/bin/../lib/gcc/mingw32/4.6.2/../../../libmingw32.a(main.o): In function `main':
C:\MinGW\msys\1.0\src\mingwrt/../mingw/main.c:73: undefined reference to `WinMain#16'
collect2: ld returned 1 exit status
make[2]: *** [../RecastDemo/Bin/RecastDemo.exe] Error 1
I'm not sure where to explore more as library order seems correct. What am i missing here?
The problem is you are missing a link library, mingw32 in this case. The easiest way to fix it is to tell CMake where to find SDL. You can do this by setting the SDLDIR environment variable (see http://cmake.org/cmake/help/v2.8.10/cmake.html#module:FindSDL). So based on your SDL install location, from your MinGW prompt:
export SDLDIR=/c/_libdist/x86/msys
Then run CMake:
cmake -G "MSYS Makefiles" ..
This should find SDL and set the SDL include directories and link libraries correctly.
However, there is a bug in CMake that passes libraries to the linker in the wrong order, see http://public.kitware.com/Bug/view.php?id=13769. The bug has been fixed but isn't in the latest release yet (2.8.10.2).
Until there's a new CMake release what you can do is edit the cached
SDL_LIBRARY value in CMakeCache.txt in your build directory and switch
the order of the SDL libraries around then run CMake again.