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

Author Topic: If you are having trouble compiling sfml on linux look here!  (Read 1892 times)

0 Members and 1 Guest are viewing this topic.

adamkwal

  • Newbie
  • *
  • Posts: 11
    • View Profile
Hey guys, recently I have installed linux mint 9 and I could not get sfml to compile and work on it.  I searched the forums, and asked a few questions and eventually figured it out.  I have decided to write this simple tutorial to save you the massive headache that me and others like me have had trying to do this task. Lets get started :P

First thing is first, make sure you have all of these packages installed

    build-essential
    mesa-common-dev
    libx11-dev
    libxrandr-dev
    libgl1-mesa-dev
    libglu1-mesa-dev
    libfreetype6-dev
    libopenal-dev
    libsndfile1-dev


If your linux distribution has a package manager for them, I would look there. Otherwise just google them and manually install them.

Now download sfml version that you would like to use, for this example I will be using sfml2. http://sfml.svn.sourceforge.net/viewvc/sfml/branches/sfml2.tar.gz?view=tar, but you can use any version you want http://www.sfml-dev.org/download.php

Now open up your terminal and navigate to your sfml-x.y directory, and type these following commands
    make clean
    make

If this works and you receive no errors then just type: sudo make install

However if you are like me, then you will receive tons of errors when trying to "make" the directory.  To fix these errors you will need to install the libraries that the errors are asking for.  For example I was getting errors about png and jpg images, so I went to my package manager and installed the png/jpg libraries.  I kept on doing this until all of the packages I was missing were installed.  Finally when I typed: make clean -> make it compiled!  Then I wrote sudo make install and everything installed.  

Next I was starting to get errors that the system.so.2.0,graphics.so.2.0,etc were not found.  To solve this I had to log in as root, here are the steps
    Open terminal
    Type: sudo su
    Type: passwd
    Close terminal

Now log out of your session, and relog as root(the password is what you set up in the above steps)

Navigate to your usr/local/lib folder and copy all of the files(system.so.2.0,etc) to the directory usr/lib

Now open code::blocks and go to setting->Compiler Settings
Go to Search directories and under compiler and your sfml-x.y/include.  Then in linker add your sfml-x.y/lib.

Finally in Linker Settings->Other linker options  add these and whatever else you need: -lsfml-graphics, -lsfml-window, -lsfml-system, etc->Press OK

You should now be able to compile/run all sfml code.

To test if it works type this, and compile it
Code: [Select]

#include <SFML/Graphics.hpp>

using namespace sf;

int main()
{
// Create the main rendering window
    sf::RenderWindow App(sf::VideoMode(800, 600, 32), "SFML Graphics");
   
    // Start game loop
    while (App.IsOpened())
    {
        // Process events
        sf::Event Event;
        while (App.GetEvent(Event))
        {
            // Close window : exit
            if (Event.Type == sf::Event::Closed)
                App.Close();
        }

        // Clear the screen (fill it with black color)
        App.Clear();

        // Display window contents on screen
        App.Display();
    }

    return EXIT_SUCCESS;
}


Hopefully this helped :lol:.  If you are still getting errors with "make" please post them as a comment and hopefully someone can help you.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
If you are having trouble compiling sfml on linux look here!
« Reply #1 on: May 10, 2010, 08:38:40 am »
Why are there so many different posts about that today? :?

Anyway, have a look at this post:
http://www.sfml-dev.org/forum/viewtopic.php?p=16996#16996
Laurent Gomila - SFML developer

 

anything