Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ld linker error "cpu model hidden symbol"

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?

like image 499
FreelanceConsultant Avatar asked Aug 02 '16 18:08

FreelanceConsultant


People also ask

What is a linker (LD) error?

This phrase indicates that you have a linker (ld) error, not a compiler error. Linker errors occur when g++ tries to combine all of your.o files into an executable file. Linker errors CANNOT be fixed by guarding header files or by changing which header files are included in your.cpp file.

What does LD return 1 mean in compiler?

Commonly used words and phrases found in the compiler and linker error messages. identifier -- the name of a class, struct, function or variable collect2: ld returned 1 exit status -- usually found as the last line of the error. This phrase indicates that you have a linker (ld) error, not a compiler error.

What does LD returned 1 exit status mean?

collect2: ld returned 1 exit status -- usually found as the last line of the error. This phrase indicates that you have a linker (ld) error, not a compiler error.


2 Answers

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)

like image 91
Joshua Whitley Avatar answered Oct 07 '22 00:10

Joshua Whitley


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

like image 29
Guss Avatar answered Oct 07 '22 00:10

Guss