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

Author Topic: [SOLVED] Cannot link against SFML2 on Linux  (Read 4039 times)

0 Members and 1 Guest are viewing this topic.

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
[SOLVED] Cannot link against SFML2 on Linux
« on: August 05, 2012, 10:08:18 am »
Hey!
I feel like issues like these are discussed here everyday, but I cannot find any solution.

I'm trying to build JSFML for Linux (Ubuntu 12.04 LTS, 64-bit), but I keep getting undefined references for every single SFML symbol. I built SFML using CMake (no modifications or special flags set, it used to work like this before) and without errors, then copied the binaries into my JSFML dependency directories.

The build command is as follows:
Code: [Select]
[exec] Executing 'g++' with arguments:
     [exec] '-I/home/pdinklag/JSFML/include'
     [exec] '-I/home/pdinklag/JSFML/sfml/include'
     [exec] '-I/usr/lib/jvm/java-6-openjdk-amd64/include'
     [exec] '-I/usr/lib/jvm/java-6-openjdk-amd64/include/linux'
     [exec] '-shared'
     [exec] '-fPIC'
     [exec] '-o/home/pdinklag/JSFML/out/bin/linux_x64/libjsfml.so'
     [exec] '-Wl,-no-undefined,-L/home/pdinklag/JSFML/sfml/bin/linux_x64,-lstdc++,-lsfml-system,-lsfml-window,-lsfml-graphics,-lsfml-audio'
     (... list of cpp files to compile)
     [exec] The ' characters around the executable and arguments are
     [exec] not part of the command.

I get this error for seemingly every SFML symbol:
Code: [Select]
[exec] /tmp/cc6x6B0J.o: In function `JSFML::Color::ToSFML(JNIEnv_*, _jobject*)':
     [exec] Color.cpp:(.text+0x1e1): undefined reference to `sf::Color::Color(unsigned char, unsigned char, unsigned char, unsigned char)'
     [exec] /tmp/cc4jQlbv.o: In function `JSFML::RenderStates::ToSFML(JNIEnv_*, _jobject*)':
     [exec] RenderStates.cpp:(.text+0x201): undefined reference to `sf::RenderStates::RenderStates(sf::BlendMode, sf::Transform const&, sf::Texture const*, sf::Shader const*)'
     [exec] /tmp/ccIR6QV3.o: In function `JSFML::Time::ToSFML(JNIEnv_*, _jobject*)':
     [exec] Time.cpp:(.text+0xeb): undefined reference to `sf::microseconds(long long)'
     [exec] /tmp/ccIR6QV3.o: In function `JSFML::Time::FromSFML(JNIEnv_*, sf::Time const&)':
     [exec] Time.cpp:(.text+0x10a): undefined reference to `sf::Time::asMicroseconds() const'
     [exec] /tmp/ccgkSzcD.o: In function `JSFML::Transform::ToSFML(JNIEnv_*, _jobject*)':
     [exec] Transform.cpp:(.text+0x17c): undefined reference to `sf::Transform::Transform(float, float, float, float, float, float, float, float, float)'
(...)

Obviously, it fails to link against any SFML library.

Now, I made sure that the shared object files are actually found by the linker using this:
Code: [Select]
pdinklag@pdinklag-linux:~/JSFML$ ld -L/home/pdinklag/JSFML/sfml/bin/linux_x64 -lsfml-system -lsfml-window -lsfml-graphics -lsfml-audio
ld: warning: cannot find entry symbol _start; not setting start address

I'd be getting a "library not found" message if anything was actually not found, so that's cleared out.

Now I'm pretty much out of ideas and feel like something went wrong linking SFML itself. As mentioned, I used the default CMake setup that's on github, no special flags set or anything, and it used to work fine before. Is there anything I missed, anything I need to make sure?
« Last Edit: August 05, 2012, 04:43:53 pm by pdinklag »
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Cannot link against SFML2 on Linux
« Reply #1 on: August 05, 2012, 12:19:26 pm »
You must link SFML libraries in the right order (libraries that depend on others first): audio graphics window system.
Laurent Gomila - SFML developer

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Cannot link against SFML2 on Linux
« Reply #2 on: August 05, 2012, 01:15:52 pm »
Oh, good to know in general, always thought it was the other way round...

Anyway, this did not seem to help at all, same output. I noticed this:
Code: [Select]
pdinklag@pdinklag-linux:~/JSFML$ ld -lstdc++
ld: cannot find -lstdc++
pdinklag@pdinklag-linux:~/JSFML$ ld -lstdc++6
ld: cannot find -lstdc++6
I'm not sure why this is, because I have libstdc++6 installed. Might it have anything to do with it? (I doubt it, cause the "undefined symbols" are the SFML ones, but SFML compiled and linked fine).
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Cannot link against SFML2 on Linux
« Reply #3 on: August 05, 2012, 04:00:39 pm »
What if you try with the precompiled RC instead of your own version?
Laurent Gomila - SFML developer

pdinklag

  • Sr. Member
  • ****
  • Posts: 330
  • JSFML Developer
    • View Profile
    • JSFML Website
Re: Cannot link against SFML2 on Linux
« Reply #4 on: August 05, 2012, 04:43:44 pm »
Good idea trying that. I had the same behaviour, BUT I managed to fix the issue!

Quote from: Laurent
You must link SFML libraries in the right order (libraries that depend on others first)
This helped after all!
When I put the source files before the linker arguments (so that the object files are passed to the linker BEFORE the SFML libs), it linked fine. So, that statement goes for anything, not just the SFML libs.

Thanks for the help! :)
JSFML - The Java binding to SFML.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: [SOLVED] Cannot link against SFML2 on Linux
« Reply #5 on: August 05, 2012, 06:31:47 pm »
Oh, I didn't know that. gcc is so picky :P
Laurent Gomila - SFML developer