c++linkercmakeshared-librariesogre3d

C++ Linking errors using third party library


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!


Solution

  • 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