Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: undefined reference with peculiar name  (Read 2781 times)

0 Members and 1 Guest are viewing this topic.

greenmuzz

  • Newbie
  • *
  • Posts: 4
    • View Profile
undefined reference with peculiar name
« on: May 11, 2016, 03:40:23 pm »
Hi,

I can't yet create a minimal example that reproduces this linker error - to my annoyance splitting my renderer from anything else allows successful compilation of a trivial usage of it. While I search for a minimal example that reproduces the error, is there anyone out there who can perhaps parse and understand this cryptic undefined reference so I might have a better idea what to look for?

g++, Ubuntu 16.04, everything installed through package manager.

/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libsfml-window.so: undefined reference to symbol '_ZN2sf6StringC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6locale'
/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libsfml-system.so: error adding symbols: DSO missing from command line

nicox11

  • Jr. Member
  • **
  • Posts: 51
    • View Profile
Re: undefined reference with peculiar name
« Reply #1 on: May 11, 2016, 03:56:34 pm »
I found this using a google search with your error :
http://stackoverflow.com/questions/19901934/strange-linking-error-dso-missing-from-command-line#19905704

May be not the problem though

greenmuzz

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: undefined reference with peculiar name
« Reply #2 on: May 11, 2016, 04:04:27 pm »
Thanks, finally found it.

For some reason, on my Mac, it compiled, meaning I didn't consider that the order of my libraries could be the issue (because, as I say, it was linking quite happily). This also reinforced by miss-remembered belief about what order the libraries (mine vs. sfml) should be listed in.  Basically, I needed to put my library first because it depended on SFML, and I had it after (because I  have a bad memory). I knew it would end up being something that trivial, such a pain that having the wrong order worked elsewhere.

hey ho.

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: undefined reference with peculiar name
« Reply #3 on: May 12, 2016, 10:25:38 am »
The "cryptic reference" you see is just the C++ name mangling, adding additional information to the actual (c style) function/export name to allow additional things like overloaded functions (since C doesn't support that).

You can read more about it on Wikipedia: https://en.wikipedia.org/wiki/Name_mangling

If you encounter something like this, try to differentiate between decoration/garbage and actual names. These are (at least for GCC and a few other toolchains) always precedented by the length of the actual name written in a decimal number, in this example it's enough to read the first two:

2sf
5String

So the culprit was indeed "sf::String" (or some part of it).

The far easier - and better - approach is to use a tool such as "c++filt":

Code: [Select]
user@host ~ $ c++filt _ZN2sf6StringC1ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6locale
sf::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::locale const&)

As you can see, it tells you the exact signature of the reference missing.

As for order of libraries, think of the linker never "looking back". So if some dependency needs export x, make sure to name the library with export x later (i.e. on the right side).

 

anything