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

Author Topic: Linker Errors Ubuntu  (Read 3184 times)

0 Members and 1 Guest are viewing this topic.

Grunz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Linker Errors Ubuntu
« on: March 11, 2012, 11:22:10 pm »
System: Ubuntu 11.10 64 bit
cpu: AMD Phenom(tm) II X4 965 Processor × 4
I installed the 2.0 snapshot LaurentGomila-SFML-2de690f via cmake / Makefile. Had it make everything and did a "sudo make install"
This all looked good and /usr/local/lib/ now contains:
Code: [Select]
libsfml-audio.so         libsfml-network.so.2.0  libsndfile.la
libsfml-audio.so.2       libsfml-system.so       libsndfile.so
libsfml-audio.so.2.0     libsfml-system.so.2     libsndfile.so.1
libsfml-graphics.so      libsfml-system.so.2.0   libsndfile.so.1.0.25
libsfml-graphics.so.2    libsfml-window.so       pkgconfig
libsfml-graphics.so.2.0  libsfml-window.so.2     python2.6
libsfml-network.so       libsfml-window.so.2.0   python2.7
libsfml-network.so.2     libsndfile.a            site_ruby
also /usr/local/share/SFML/examples/ has:
Code: [Select]
ftp  opengl  pong  shader  sockets  sound  sound-capture  voip  window  X11
However, if I try to compile an example myself like this:
Code: [Select]
gcc Window.cpp
/tmp/ccygC6cP.o: In function `main':
Window.cpp:(.text+0x3e): undefined reference to `std::allocator<char>::allocator()'
Window.cpp:(.text+0x53): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)'
 ... (more "undefined" errors)
/tmp/ccygC6cP.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
So somehow "make" did know how to compile the examples, but I do not.  :oops:

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Linker Errors Ubuntu
« Reply #1 on: March 12, 2012, 12:30:29 am »
Use g++ instead of gcc. Also, you will need to throw in some flags like -lsfml-system and such.

Do make VERBOSE=1 to see what make is doing.

Grunz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Linker Errors Ubuntu
« Reply #2 on: March 13, 2012, 03:15:49 am »
OK, digging recursively through make and cmake calling each other recursively it looks like using full path to SFML libraries is required. So
Code: [Select]
g++ -lsfml-window -lsfml-graphics -lsfml-system -lGLU -lGL -lSM -lICE -lX11 -lXext -lpthread -lrt -lXrandr -o window Window.cppcompiles but linker fails. As mentioned already:
Code: [Select]
g++ -c Window.cppdoes create the .o just fine without any extra flags.
Using full path like this:
Code: [Select]
g++ -O3 Window.cpp  -o window /usr/local/lib/libsfml-window.so.2.0 /usr/local/lib/libsfml-system.so.2.0 -lGLU -lGL -lSM -lICE -lX11 -lXext -lpthread -lrt -lXrandrdoes work.
Checking "g++ -v" reveals that /usr/local/lib is not in the library path:
Code: [Select]
..
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/:/usr/lib/gcc/x86_64-linux-gnu/4.6.1/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6.1/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.6.1/:/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../:/lib/:/usr/lib/
..

Would adding /usr/local/lib help avoid those unwieldy parameters? Does someone know how to do so?

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Linker Errors Ubuntu
« Reply #3 on: March 13, 2012, 04:16:16 am »
-L/usr/local/lib

Grunz

  • Newbie
  • *
  • Posts: 3
    • View Profile
Linker Errors Ubuntu
« Reply #4 on: March 13, 2012, 10:08:04 pm »
Yes, the -L does work, but only if I then also use the battalion of "-l" parameters like this:
Code: [Select]
g++ Window.cpp  -L /usr/local/lib -lsfml-window -lsfml-graphics -lsfml-system -lGLU -lGL -lSM -lICE -lX11 -lXext -lpthread -lrt -lXrandr -o windowSo, without -L, the linker can find openGL and the other stuff all by itself, but if I use it, it no longer can.
B.t.w. ,the man/info page for gcc does only mention the existence of the -L option. It is nowhere explained what it actually does. And I can call g++ -L "nonexisting path" and will get no errors from that. :(