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

Author Topic: Linking sfml with g++  (Read 5245 times)

0 Members and 1 Guest are viewing this topic.

isReady

  • Newbie
  • *
  • Posts: 13
    • View Profile
Linking sfml with g++
« on: May 17, 2013, 03:50:50 pm »
I am not able to link the libraries of sfml...
Code: [Select]
$g++ main.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system
/usr/bin/ld: cannot find -lsfml-graphics
/usr/bin/ld: cannot find -lsfml-window
/usr/bin/ld: cannot find -lsfml-system
collect2: ld returned 1
Quote
/usr/lib$ ls | grep sfml
libsfml-audio.so.2
libsfml-audio.so.2.0
libsfml-graphics.so.2
libsfml-graphics.so.2.0
libsfml-network.so.2
libsfml-network.so.2.0
libsfml-system.so.2
libsfml-system.so.2.0
libsfml-window.so.2
libsfml-window.so.2.0
I also tried -L/usr/lib, but nothing changed.
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");
    sf::CircleShape shape(100.f);
    shape.setFillColor(sf::Color::Green);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(shape);
        window.display();
    }

    return 0;
}
 

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking sfml with g++
« Reply #1 on: May 17, 2013, 05:38:45 pm »
Why don't you have the libsfml-xxx.so symlinks? Whether you built SFML yourself, or downloaded it from the website, they should be there.
Laurent Gomila - SFML developer

AltF4ToWin

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Linking sfml with g++
« Reply #2 on: May 17, 2013, 06:58:37 pm »
Try adding a file in /etc/ld.so.conf.d called "sfml-x86.conf" with the path of the SFML object files and run ldconfig as root, see if that changes anything.

isReady

  • Newbie
  • *
  • Posts: 13
    • View Profile
Re: Linking sfml with g++
« Reply #3 on: May 17, 2013, 08:14:24 pm »
Quote
Why don't you have the libsfml-xxx.so symlinks? Whether you built SFML yourself, or downloaded it from the website, they should be there.
I installed the libsfml package of Sonkun. Strange to say, there weren't any include files so I downloaded them from the official site and extracted them to /usr/include. Where do I have to add these links? Unfortunately the package libsfml-development doesn't exist.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Linking sfml with g++
« Reply #4 on: May 17, 2013, 08:55:45 pm »
Quote
I installed the libsfml package of Sonkun. Strange to say, there weren't any include files
You should talk to Sonkun directly. He or you did something wrong; in any case, don't fight with an invalid install, fix this first ;)
Laurent Gomila - SFML developer

elhtmlnoexiste

  • Newbie
  • *
  • Posts: 1
    • View Profile
Re: Linking sfml with g++
« Reply #5 on: October 29, 2013, 06:43:11 pm »
Just as a reference. I had the exact same problem but It was my fault as I've compiled sources myself. In my case the library directory used during cmake configuration was /usr/local/lib instead of the more common /usr/lib. For me just linking with the -L option to add the correct lib directory fixed the issue:

g++ main.o -o m -L /usr/local/lib/ -lsfml-graphics -lsfml-window -lsfml-system

Hope this helps somebody else.

Cheers!