12

I'm getting an ld error when attempting to compile an sfml program on ubuntu 16.04. This is apparently a known issue, and there is supposed to be a workaround, but I don't understand what is it...

http://web.archive.org/web/20160509014317/https://gitlab.peach-bun.com/pinion/SFML/commit/3383b4a472f0bd16a8161fb8760cd3e6333f1782.patch

The error spat out by ld is

hidden symbol `__cpu_model' in /usr/lib/gcc/x86_64-linux-gnu/4.9/libgcc.a(cpuinfo.o) is referenced by DSO

There is no relevant code to this - as I understand it this error is produced on all ubuntu 16.04 systems with g++ 5, if the program to be linked contains objects such as sf::Texture and sf::Sprite. (I don't know any more detail than this.)

I have tried also compiling with g++ 4.9, but the same error occurs.

My compile line is g++-4.9 --std=c++11 -Wall main.cpp -lsfml-graphics -lsfml-window -lsfml-system -o a.out

Has anyone else experienced this error and resolved it successfully?

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225

4 Answers4

11

I've had to fix this issue several times. Instead of applying the patch, you can manually fix it by editing the file SFML/src/SFML/Graphics/CMakeLists.txt. At line 149, you will find the following:

if(SFML_COMPILER_GCC)
 set_source_files_properties(${SRCROOT}/ImageLoader.cpp PROPERTIES COMPILE_FLAGS -fno-strict-aliasing)
endif()

After the endif(), insert the following:

if(SFML_COMPILER_GCC AND BUILD_SHARED_LIBS)
    list(APPEND GRAPHICS_EXT_LIBS "-lgcc_s -lgcc")
endif()

Then, in the top-level SFML folder, run the following:

mkdir build && cd build
cmake .. -DSFML_BUILD_EXAMPLES=ON -DSFML_BUILD_DOCS=ON
make
sudo make install
sudo ldconfig

This will get it built and installed without the compiler error. (Note: Remove the -D flags from cmake if you don't want docs or examples)

Joshua Whitley
  • 1,196
  • 7
  • 21
  • That did the trick for me. Interesting thing is that examples were building just fine, pong for example. But when I tried to use these libraries in my own project - even with exact code as pong example - I was getting this error. Really strange - in one place it worked and in other with the same libraries it didn't. Anyway after that change it works in my project. – solgar Jan 05 '17 at 13:52
  • 1
    I'm quite lost on this one. Have been following these steps several times but am still getting the same error. What is the relevance between gcc and SFML? For me it doesn't seem to be any – Robin Castlin May 27 '17 at 02:47
2

I ran this in the SFML source directory before running the standard cmake...make:

curl https://gitlab.peach-bun.com/pinion/SFML/commit/3383b4a472f0bd16a8161fb8760cd3e6333f1782.patch \
  | patch -p1

and that solved the problem

Guss
  • 30,470
  • 17
  • 104
  • 128
0

I've got the same linker error when trying to build SFML 2.4.2 with examples, specifically with opengl and shader ones.

Inspired by the @Joshua solution, I tried to change the compiler from GCC to Clang. It worked.

I am sharing here because it seems to be a simpler solution if you have no restrictions to use Clang.

Just download SFML and change to its directory. And...

mkdir build && cd build
cmake .. -DSFML_BUILD_EXAMPLES=ON -DCMAKE_CXX_COMPILER=clang++
make
sudo make install
sudo ldconfig
gallo
  • 546
  • 7
  • 10
0

Removing -fvisibility=hidden from compiler options worked for me.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
anil valmiki
  • 181
  • 1
  • 11