SFML2 static linking error with mingw32: undefined references - c++

I am using Code::Blocks on 64bit Windows 7, MinGW 4.7.1.
I'm trying to get SFML 2.1 to work with MingW in codeblocks, but it's causing problems.
when i try to compile i get these errors:
undefined reference to _imp___ZN2sf6StringC1EPKcRKSt6locale
undefined reference to _imp___ZN2sf9VideoModeC1Ejjj
...
I'm linking the following libraries:
sfml-graphics
sfml-window
sfml-system
What am I doing wrong? The errors say undefined reference, but I have already follow these instructions step by step.

When trying to link the static version of the library, you'll essentially have to use the static version of the headers as well (otherwise you're essentially looking for the references at the wrong place (more specifically: with the wrong format/decoration)).
As such, when linking the static version, always make sure that SFML_STATIC is defined before you include any SFML header.
Also, make sure to link the static version of the libraries (with a -s suffixed).
Static SFML
Define SFML_STATIC.
Link to sfml-system-s, sfml-window-s, sfml-graphics-s, etc. (or their debug versions).
Dynamic SFML
Do not define SFML_STATIC.
Link to * sfml-system*, sfml-window, sfml-graphics, etc. (or their debug versions).

Related

How can I see what libraries Mingw32 links by default?

I'm using Mingw32 compiler to build a C++ app.
I'm passing -nostdlib to the linker because I only want to link the libraries I'm going to actually use.
However I'm running into a problem with the C++ standard library.
When I link with libstdc++ I get the following error:
undefined reference to '_Unwind_SjLj_Register'
So clearly libstdc++ isn't the right library to link with.
Is there any way of seeing what libraries Mingw32 links with by default when building a C++ app?
What libraries are being excluded when the flag -nostdlib is passed to linker?
Thanks.

Undefined references to "__gx_personality_sj0" and others when trying to include boost::thead in project

I've recently been trying to make use of the boost libraries and whilst I have been able to include header-only libraries just fine I'm now stuck on including the linked libraries. I've managed to use b2 to build the libraries with gcc and then link to them, but whilst trying to include thread I get these errors.
I've read that these errors can be caused by using the wrong toolset for building but I can't see how I could of got that wrong as I've only ever used mingw and I used toolset=gcc when building. Here are my toolchain executables just in case I have done something wrong there. What am I doing wrong?
Turns out my path variable was incorrect and included Haskells mingw directory instead of the one I was using. After getting rid of Haskell from my path and adding the directy of the version mingw that I was using everything worked as intended.

Link to specific stdc++ library

I have a c++ application which I am trying to build under Linux, it needs to be linked to a third party shared library, however this library has been built with a quite recent version of GCC/glibc (4.8.3/2.18). When I try and build my application using a less recent version of GCC/glibc (4.4.7/2.12), the linked phase of the build fails, with ld complaining of undefined references, which are references to functions defined in the newer libstdc++.
The third party has given me a precompiled version of libstdc++ and libgcc_s to use with the library, but how do I use these versions in my build?
How do I tell GCC to use the precompiled libraries instead of the system ones, while still using the system GCC?
I have tried using the "-nodefaultlibs" option and including "-lstdc++" and "-L" options, but it seems to have no effect on the undefined references.
Example of an error I get during linking:
undefined reference to std::__throw_bad_function_call()#GLIBCXX_3.4.14'
undefined reference to std::length_error::~length_error()#GLIBCXX_3.4.15'
I managed to get the application to build successfully by specifying the full path of the libstdc++ and libgcc_s shared objects in the objects list of the linking command (e.g. /home/mike/Downloads/libstdc++.so.6) . Going this way I didn't need to use any additional options such as "-nostdlibs" and only needed to ensure the linked shared objects were available via the LD_LIBRARY_PATH when running the application.

Issues with Boost Linking/Build in Dev-C++

I'm trying to compile a personal program that uses the Boost/Regex library in Orwell Dev-C++ with TDM-GCC 4.8.2 64 bit Release, and when I attempt to initialize a Boost::Regex object I get these error messages.
text$_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE[_ZN5boost9re_detail27cpp_regex_traits_char_layerIcEC2ERKNS0_21cpp_regex_traits_baseIcEE]+0x2b): undefined reference to `boost::re_detail::cpp_regex_traits_char_layer<char>::init()'
regex_tester_main.cpp:(.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]+0x5f): undefined reference to `boost::re_detail::raw_storage::resize(unsigned long long)'
regex_tester_main.o: bad reloc address 0x5f in section `.text$_ZN5boost9re_detail11raw_storage6extendEy[_ZN5boost9re_detail11raw_storage6extendEy]'
I've followed this guide to install Boost and I used gcc as my toolkit parameters for the bootstrap.bat and the b2 builder. I've included the include and lib paths in my includes and library options. And lastly linked the appropriate libboost_regex*.a file. Before this I tried using the mingw toolkit option for the bootstrap and gcc option for b2 like the tutorial linked above does, and encountered the same errors. Can anyone shed insight into what has gone wrong?
SOLVED!
I also have the Haskell GHC installed which comes packaged with a mingw/GCC package which was located earlier in the PATH environment variable than the TDM-GCC/minGW-64 package I was aiming to use to build Boost. And so when I specified my toolset it was targeting the wrong complier and thus when I tried to build other programs with Boost it probably ran into some name-mangling issues. I removed GHC's mingw/GCC complier package from PATH and rebuilt Boost, it complies and links fine now :).

undefined references when linking own static library that itself depends on static libraries

I wrote a static library (compiled with TDM-gcc 4.8.1 in Windows 7 for x64) that has dependencies on other static libraries. Boost libraries (locale and system) to be specific.
Since I'm building a static library I assumed that the libraries I'm dependend on would automatically included in my final .a, especially since I'm using them in my code.
But when I'm trying to build an executable that statically links to my aforementioned library there are still undefined references to some boost parts, that are definitely used in my library.
Is there a way to fix that?
Any help is gladly appreciated. Thank you
Edit:
I haven't been careful enough, because I now know what causes the problem. I'm using codeblocks and all the necessary arguments for building the archive are declared in the project prooperties. But codeblocks doesn't even call the linker when building my library. Instead it calls ar.exe and passes all object files of my project. That way, no external library are ever included. So, I have too look for away to tell codeblocks to build the library in the right way..
Your executable needs to link against all the relevant libraries, including the ones it directly depends on, plus the ones it indirectly depends on. When you link a static library you typically do not embed other static libraries within it.