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

Author Topic: Linux - GCC 4.7.2 - SFML 2.0 RC - undefined reference to sf::Window::Window(...)  (Read 3120 times)

0 Members and 1 Guest are viewing this topic.

Superpelican

  • Newbie
  • *
  • Posts: 8
    • View Profile
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/.
Manjaro Linux KDE 0.8.3 - GCC 4.7.2 x86_64 - KDE 4.10 - Kate Text Editor (dev environment)

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
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. :-\
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
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.
Laurent Gomila - SFML developer

Superpelican

  • Newbie
  • *
  • Posts: 8
    • View Profile
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?
« Last Edit: February 20, 2013, 04:29:35 pm by Superpelican »
Manjaro Linux KDE 0.8.3 - GCC 4.7.2 x86_64 - KDE 4.10 - Kate Text Editor (dev environment)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
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 ;)
Laurent Gomila - SFML developer

Superpelican

  • Newbie
  • *
  • Posts: 8
    • View Profile
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.  ;)
Manjaro Linux KDE 0.8.3 - GCC 4.7.2 x86_64 - KDE 4.10 - Kate Text Editor (dev environment)

 

anything