C++ Linking errors using third party library - c++

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

Related

how do I eliminate linker error mingw32/bin/ld.exe: cannot find -lSDL

I am trying to build SDL for use with Eclipse. I am trying to remove this linker error:
Beginning Compilation
21:15:53 **** Incremental Build of configuration Debug for project CMD ****
Info: Internal Builder is used for build
g++ "-IC:\\MinGW\\include\\SDL2" -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\CMD.o" "..\\src\\CMD.cpp"
g++ -o CMD.exe "src\\CMD.o" -lmingw32 -lSDL -lSDL2main -lSDL2
ERROR(s):
c:/mingw/bin/../lib/gcc/mingw32/5.3.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL
collect2.exe: error: ld returned 1 exit status
21:15:54 Build Finished (took 1s.36ms)
The most pertinent SO archive source I researched didn't seem to have an actionable answer for my problem, though it had the exact same problem/error:
title --
producing the same error message:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL.
If you click to the authors "solution" for the same error as mine its not clear to me how he solved it.
Any help?
Problem solved, SDL2 awesome. Ok:
c:/mingw/bin/../lib/gcc/mingw32/4.7.0/../../../../mingw32/bin/ld.exe: cannot find -lSDL.
Reinstallation of SDL2 avoiding binary conflict between SDL files and SDL2 files
as keltar mentioned resolved the immediate problem, and the problem built with no errors!Fixing what was in the braces unmasked new problem: crashing. I stripped the program to bare bones and concluded the crashing was outside of the code since it was occurring even without code.
To solve the new problem would need to go the SDL2 distribution file (the one copied to MinGW) and copy the SDL2.dll from it [DLL from distributable][1]--- by dragging the file over your debug and/or release folders where the .exe file lives.(.exe + dll -> right?) moving dll to exes. Build/Run the program
it should work!
You should see a Welcome message!
https://www.caveofprogramming.com/c-for-complete-beginners/setting-up-sdl-windows.html

/usr/bin/ld: cannot find happens only when the library has few versions (i think)

I'm trying to link opencv libraries in eclipse for a c++ project.
When I link libraries that have one instance in the folder it seems to recognize it, but doesn't recognize when the libraries have few instances (perhaps the term instance isn't so accurate, i'm not quite sure what is the meaning of these different versions of libraries).
Therefore the problem doesn't seem to be related to misuse of lib or wrong path, as i have seen in other questions.
This is what I get when building the project:
12:33:17 **** Incremental Build of configuration Debug for project Test2 ****
make all
Building target: Test2
Invoking: GCC C++ Linker
g++ -L/usr/local/Matlab/2013b/bin/glnxa64 -o "Test2" ./BilateralFilter.o ./main.o ./stdafx.o -lopencv_core -lmwvision_res -lmwvision -lopencv_imgproc -lopencv_highgui
/usr/bin/ld: cannot find -lopencv_core
/usr/bin/ld: cannot find -lopencv_imgproc
/usr/bin/ld: cannot find -lopencv_highgui
collect2: error: ld returned 1 exit status
make: *** [Test2] Error 1
as you can see, the mwvision doesn't seem to have a problem, but the others do, and I think it has to do with them existing in multiple versions in the directory (but perhaps i'm wrong).
opencv_core, opencv_imgproc and opencv_highgui all have .so.2.4 and .so.2.4.2 versions.
These two links unfortunately did not provide an answer:
ld linkage problems: /usr/bin/ld: cannot find [libraryname]
/usr/bin/ld: cannot find shared library
Also I will mention that I have no use in Matlab, it's just where I found the libraries of opencv.
opencv_core, opencv_imgproc and opencv_highgui all have .so.2.4 and .so.2.4.2 versions.
If you read this description of external library versioning, you'll understand that the .so.2.4 is a runtime name of the library, and not its link-time name.
In order to link, you need .so (without the version suffix).
Having .so.2.4 but not .so usually comes about when you have e.g. libopencv-core package installed, but not libopencv-core-dev. The solution is to install the latter.

Qt Creator can't find library

I'm using ubuntu(32 bit) on virtualbox. I am trying to add a the rtlsdr library but Qt creator can't find the rtlsdr library.
The library is located in /usr/local/lib/librtlsdr.so and I have tried adding the following to my .pro file
LIBS += -L/usr/local/lib -lrtlsdr
INCLUDEPATH +=usr/local/lib
But I get the following error:
/home/luis/qt-bbb/gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin/arm-linux-gnueabihf-g++ -Wl,-rpath-link=/home/luis/qt-bbb/tslib/lib -Wl,-rpath,/opt/qt-arm/lib -o qt-test main.o mainwindow.o moc_mainwindow.o -L/home/luis/qt-bbb/tslib/lib -L/opt/qt-arm/lib -L/home/luis/qt-arm/rtl-sdr/build/src/ -lrtlsdr -lQtGui -L/opt/qt-arm/lib -L/home/luis/qt-bbb/tslib/lib -lQtNetwork -lQtCore -lpthread
/home/luis/qt-bbb/gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: *skipping incompatible /home/luis/qt-arm/rtl-sdr/build/src//librtlsdr.so when searching for -lrtlsdr*
/home/luis/qt-bbb/gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: *skipping incompatible /home/luis/qt-arm/rtl-sdr/build/src//librtlsdr.a when searching for -lrtlsdr*
Makefile:105: recipe for target 'qt-test' failed
/home/luis/qt-bbb/gcc-linaro-arm-linux-gnueabihf-4.7-2013.04-20130415_linux/bin/../lib/gcc/arm-linux-gnueabihf/4.7.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lrtlsdr
collect2: error: ld returned 1 exit status
make: *** [qt-test] Error 1
I'm using ubuntu 32bit to cross compile for my beaglebone running debian. Deploying on my beaglebone works ok and I verified the libraries are 32 bit so I don't know why it can't find them or why it's giving me “skipping incompatible” message. I also tried adding them by right clicking on the .pro->add library but still can't find them.
skipping incompatible tells you the library cannot be linked. Probably compiled with the wrong compiler?
– Sebastian Lange
Ok i figured out my problem, the library was built for x86 and not arm. Thanks for the hints! – luismbedder

Static-linking of SDL2 libraries

I am using Windows 7, Code::Blocks and MinGW. I have little to no experience when it comes to compiling/building anything, especially when Code::Blocks doesn't use makefiles.
I downloaded SDL2-devel-2.0.0-mingw.tar.gz (SDL Development Libraries) from http://www.libsdl.org/tmp/download-2.0.php, and I'd like to create a standalone executable using SDL2 libraries, but so far I've always had to bundle the SDL2.dll file with the executable to make it work.
I've heard that I can not static-link dynamic libraries, so my only option seems to be doing something with the source files using the file SDL2-2.0.0.tar.gz (Source Code) from the link I mentioned above. However, I do not know what I should do with those.
What I managed to try with the source files is importing the Visual Studio project to Code::Blocks and building it, but it tells me "sdl-config No such file or directory" (I do not know what triggered that). I'm also not sure if building merely gives me an executable, with which I do not know what I can do to link it to my own executable.
A fool proof idiot's step by step guide would be the best bet to solve this case.
EDIT:
I managed to compile the SDL libraries with the guide Jonas provided, and got a libSDL2.a file.
At first I only added the path of libSDL2.a to "Link libraries:" -section of Code::Blocks, but I got a bunch of errors such as "SDL_Init() not declared in this scope".
In addition to the libSDL2.a path, I also added the path of SDL2-2.0.0\include to the Compiler's search directory as well as the path of SDL2-2.0.0\build.libs to the Linker's search directory. I also wrote this to my test file: #include "SDL.h". My test file now looks like this:
#include "SDL.h"
int main( int argc, char* args[] ) {
//Start SDL
SDL_Init( SDL_INIT_EVERYTHING );
//Quit SDL
SDL_Quit();
return 0;
}
It appears it did fix the declaration problem, but now Code::Blocks opened a SDL_mmjoystick.c file and gave me even more errors: "undefined reference to 'waveInClose#4'", "undefined reference to 'waveOutClose#4'", "undefined reference to 'joyGetNumDevs#0'" and tons of other ones.
Here's a screenshot of what's happening, note the different color of #include texts, I'm not sure why that happens: http://gyazo.com/00656a9c1e57a2bd0db1414fa7d68ced.png
I am not sure how to correctly take this library into use. Any help in this case, or should I make another question for it?
EDIT:
I added -lSDL2 to the linker options and deleted the other parameters. Now it builds fine:
mingw32-g++.exe -Wall -fexceptions -g -IC:\Users\User\Desktop\SDL2-2.0.0\include -c "C:\Users\User\Desktop\CppProjects\SDL project\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -Wall -fexceptions -g -IC:\Users\User\Desktop\SDL2-2.0.0\include -c "C:\Users\User\Desktop\CppProjects\SDL project\thetestfile.cpp" -o obj\Debug\thetestfile.o
mingw32-g++.exe -LC:\Users\User\Desktop\SDL2-2.0.0\build\.libs -o "bin\Debug\SDL project.exe" obj\Debug\main.o obj\Debug\thetestfile.o -lSDL2 ..\..\SDL2-2.0.0\build\.libs\libSDL2.a C:\Users\User\Desktop\SDL2-2.0.0\build\.libs\libSDL2.a -mwindows
Output size is 945.80 KB
Process terminated with status 0 (0 minutes, 1 seconds)
0 errors, 0 warnings (0 minutes, 1 seconds)
But when I try to run it, it says my computer lacks SDL2.dll, while the whole point was to static-link.
So currently I have the path to build/.libs in my Link libraries -settings, -lSDL2 in the Other linker options, and for search directories I have the path to SDL2-2.0.0/include for the compiler and SDL2-2.0.0/build/.libs for the linker.
In the build/.libs directory I can also see libSDL2.a, libSDL2.dll.a, libSDL2.la and libSDL2.lai files, which I don't know what they are.
It's not necessary to recompile the library,
SDL2 is given with static-link library named "libSDL2.a"
on the folder "SDL2-2.0.0\i686-w64-mingw32\lib\".
Just be sure to add these options to the linker :
"-lmingw32 -lSDL2main -lSDL2 -mwindows -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid -static-libgcc"
on Code:Blocks at "Project / Build Options... / Linket settings / Other linker options"
These options allow you to link with what SDL2.dll was using.
You can retreive them on the file "SDL2-2.0.0\i686-w64-mingw32\bin\sdl2-config"
The magical trick is to delete or rename the file "libSDL2.dll.a"
on the folder "SDL2-2.0.0\i686-w64-mingw32\lib\".
I added a "-" before to keep it in case I need it.
I don't know why this librairy overcomes the other and a clue would be appreciated.
I tried with Code::Blocks 12.11 MinGW32 and it worked.
If you run with some projects that use dynamic-link
and some other which use static-link, you will have to
keep your librairies in two different folders knowing that
"libSDL2main.a" will be in those two.
Sorry for my writing, I'm not used to write in english.
Mike

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries I need to include.
I currently have "opengl32", "fltk_gl", "glu32", and "fltk" included (-l), each of which seem to reduce the number of errors. I compiled FLTK using make with no specified options. Including all of the produced library files doesn't fix the problem, and I'm convinced that it's just some Windows specific problem.
Compile log:
**** Build of configuration Debug for project CG5 ****
make all
Building target: CG5.exe
Invoking: Cygwin C++ Linker
g++ -o"CG5.exe" ./src/draw_routines.o ./src/gl_window.o ./src/my_shapes.o ./src/shape.o ./src/shapes_ui.o ./src/tesselation.o -lopengl32 -lfltk_z -lfltk_gl -lglu32 -lfltk
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x197): undefined reference to `_SelectPalette#12'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x1a7): undefined reference to `_RealizePalette#4'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x1fe): undefined reference to `_glDrawBuffer#4'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x20d): undefined reference to `_glReadBuffer#4'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x23a): undefined reference to `_glGetIntegerv#8'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x2c3): undefined reference to `_glOrtho#48'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/../../../libfltk_gl.a(Fl_Gl_Window.o):Fl_Gl_Window.cxx:(.text+0x2f3): undefined reference to `_SwapBuffers#4'
...and lots more
Thanks a ton for the help.
EDIT: These first few lines are obviously OpenGL related, although I'm still not sure what additional libraries need to be included.
Just a guess: your makefile was written for Linux, and on Cygwin some libraries are either missing or in a different place. You're going to have to examine the makefile, locate the missing libraries, and either move the libs to where the makefile expects them or change the makefile to look in the right place.
The libraries it needs are listed on the line starting g++ (prepend 'lib' to the names after the -l flags)
Sorry for the lack of closure, but I just booted into my Linux netbook and got it working.
-lfltk -lfltk_gl -lGLU -lGL -lXext -lX11 -lm