SFML community forums

Help => Window => Topic started by: Superpelican on February 20, 2013, 02:57:32 pm

Title: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)
Post by: Superpelican on February 20, 2013, 02:57:32 pm
Hello everyone,

I'm trying to compile the SFML 2 tutorial page' s window example:
#include <SFML/System.hpp>
#include <SFML/Window.hpp>

int main()
{
    sf::Window window(sf::VideoMode(800, 600), "My window");

    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }
    }

    return 0;
}
 

Using:
g++ -o SFML2_test ./SFML2_test.cpp -lsfml-window -lsfml-system
But I'm getting:
/tmp/ccBlNedo.o: In function `main':
SFML2_test.cpp:(.text+0x12d): undefined reference to `sf::Window::Window(sf::VideoMode, sf::String const&, unsigned int, sf::ContextSettings const&)'
collect2: error: ld returned 1 exit status

SFML 2.0 is now the only version on my system. I installed it via my package manager and the .so' s are in /usr/lib/.
Title: Re: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)
Post by: eXpl0it3r on February 20, 2013, 03:08:45 pm
It works fine on my end.

You should definitely learn how to solve linking problems on your own. They are mostly always related to your building environment and not much we can help.
I now either guess that you're object file is outdated or that your SFML libraries are not build correctly, but since it's definitely not the code, I can't help you further. :-\
Title: Re: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)
Post by: Laurent on February 20, 2013, 03:19:49 pm
You got it from the package manager? I wonder which distribution has SFML 2 in its repositories... and which revision it is based on ???

You should rather compile it yourself.
Title: Re: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)
Post by: Superpelican on February 20, 2013, 04:03:59 pm
I got it from the Manjaro Linux repositories (Manjaro Linux is based on Arch Linux, but has it' s own repositories, which lag behind around a few days or weeks compared to the official Arch repositories).
 pacman tells me that the package I installed is version 2.0RC1-3

I had already suspected that it might be that the version in the repositories is to old. And therefore I had built my own copy (latest dev snapshot - today) with CMake. But it had similiar problems.

I've also tried sfml-git (which' s in the AUR) and that cloned the latest SFML2.0 version from GIT, but that also gave linking problems.


Ok, I've now build my own SFML 2.0 copy (source from GitHub page, latest development snapshot). My program now succesfully links, but upon running ./myprogram I get the "error while loading shared libraries: no such file or directory"-error. The .so' s (and yes they have the correct name  ;) ) are in /usr/local/lib/. The linker should search in /usr/local/lib/ according to what I've read and adding the -L/usr/local/lib/ flag also doesn't help.

Why doesn't the linker find the .so' s?
Title: Re: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)
Post by: Laurent on February 20, 2013, 10:36:22 pm
If your program links, it's not about the linker. It rather fails to load the dependencies, so it's the library loader (ld) which fails to search in /usr/local/lib. Google will tell you how to add search paths to ld ;)
Title: Re: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)
Post by: Superpelican on February 21, 2013, 12:15:50 pm
Thanks, I added /usr/local/lib/ to /etc/ld.so.conf (sudo nano /etc/ld.so.conf) and ran sudo ldconfig. And now the executable finds the SFML .so' s.  ;)