-2

What do these errors mean? after having worked on a project a very long time 2+ years, and then changing to have the compiler follow c++14 standards, my project now does not compile and now I'm left anxious not knowing.

the error(s):

undefined reference to `_imp___ZN2sf7Texture12loadFromFileERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKNS_4RectIiEE'|

Demangled that is

_imp__sf::Texture::loadFromFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, sf::Rect<int> const&)

My compiler Settings

Have g++ follow C++ 14

Linker Settings:  (the dependencies order SFML requires)  sfml-graphics  
                  sfml-window
                  sfml-system
                  sfml-audio

Compiler: C:\CodeBlocks\SFML-2.4.2\include
Linker:   C:\CodeBlocks\SFML-2.4.2\lib
Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
S_BISHOP
  • 31
  • 6
  • 2
    Are you mixing code that was compiled with/without C++14 enabled? – Paul Floyd Oct 03 '18 at 12:35
  • 2
    Are you sure you're linking to a lib that's been compiled with your C++14 compiler? – Bathsheba Oct 03 '18 at 12:35
  • 2
    What you mean "changing to have the compiler follow c++14 standards"? Did you just add `-std=c++14` to a build that works without it? Or is it an entirely new system with fresh libraries, etc.? – Fire Lancer Oct 03 '18 at 12:36
  • 2
    What *exactly* did you change? – Some programmer dude Oct 03 '18 at 12:37
  • Previously I thought i had the compiler set to follow C++14 standards, apparently not, i never realised, The project compiled and built fine day to day, but i have no idea what standard i was actually following?, i wish i knew, or could just rollback to a last working state a day, to get back on track with developement. thanks everyone for the feedback – S_BISHOP Oct 03 '18 at 12:41
  • I'd guess it's the __cxx11: https://stackoverflow.com/a/33395489 – Rup Oct 03 '18 at 12:41
  • It couldnt have been c++11 because ive used keyword auto multiple times in the project, it must be SFML ? – S_BISHOP Oct 03 '18 at 12:44
  • is SFML 2.4 compatable with C++14, is that the issue do you think ? im asking as genuine as i can because i honestly dont know. – S_BISHOP Oct 03 '18 at 12:47
  • @Paul Floyd Thanks for the edit and enlightening me about the error. – S_BISHOP Oct 03 '18 at 12:54
  • @NathanOliver did most of the editing. – Paul Floyd Oct 03 '18 at 12:56
  • Your library and program are linked against two different versions of the standard library. Are you using different compilers for each, or are you on a mac, updated xcode, and have not recompiled the library? – Richard Hodges Oct 03 '18 at 12:59
  • @FireLancer I defaulted the compiler just in case, and the option Have g++ follow C++ 14 is a valid choice, if i understood that correctly, my apologies if not. – S_BISHOP Oct 03 '18 at 13:00
  • @RichardHodges If understood correctly I am using Windows 10, Mingw GCC. What do you mean by 2 different versions of the standard libary ? you may be right and i may not be aware of that. – S_BISHOP Oct 03 '18 at 13:03
  • @S_BISHOP C++11 supports "auto". The SMFL library you have on your machine is not built/supported by C++14, that's where the errors comes from. Please also start using source code managment (e.g. git) so you can at least roll back your own project to whatever worked before you changed something. – nos Oct 03 '18 at 13:10
  • @S_BISHOP there are 3 common versions of the C++ standard library. Windows, libc++ and libstdc++. In addition, these libraries changed semantically in the transition between c++03 and c++11. All libraries in an application must be compiled with the same library and (ideally) against the same standard. In particular, compiling c++11 programs against a library compiled in c++03 is asking for trouble. – Richard Hodges Oct 03 '18 at 13:13
  • @nos Thanks, and noted must use version control. – S_BISHOP Oct 03 '18 at 13:16
  • @nos "The SMFL library you have on your machine is not built/supported by C++14, that's where the errors comes from." If thats honestly the entirety of the error source i am going to be so happy. I now understand and am aware of that dependency thanks. – S_BISHOP Oct 03 '18 at 13:27

2 Answers2

3

Try adding -DGLIBCXX_USE_CXX11_ABI=0 to your compiler switches (not sure how to do that with CodeBlocks).

See details here and here.

Paul Floyd
  • 5,530
  • 5
  • 29
  • 43
2

An undefined reference could be a compiler version or config incompatibility between when SFML was compiled and you compiling your project now. If you downloaded a binary build of SFML it should say exactly which compiler and version it works with. If you built SFML from source, then simply rebuilding it with your current compiler configuration should fix it.

Generally adding -std=c++14 or such works (on the exact same compiler with the same standard library), but there are edge cases such as when a library uses typedefs or functions protected by macros to use newer types in the interface when available. And if the compiler or library versions changed then there are many more considerations.

Fire Lancer
  • 29,364
  • 31
  • 116
  • 182