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

Author Topic: I cannot figure out how to compile the sample SFML program in Linux  (Read 18107 times)

0 Members and 1 Guest are viewing this topic.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
At the moment I'm just trying to compile the sample program from this page: http://www.sfml-dev.org/tutorials/2.1/start-linux.php.  I've been using the 32-bit Linux GCC build under the downloads section, which I think is what the tutorial refers to as the "SDK."  I'm running Ubuntu 12.04 LTS inside VMware Player 5.0.2 on my Windows 7 Professional 64-bit laptop.  All of these things I downloaded and/or updated within the last 24 hours.

For a while I tried to do what the tutorial said, and one of my many guesses was that it wanted me to put the contents of SFML-2.1/include/SFML into /usr/include/SFML and the contents of SFML-2.1/lib/ into /usr/lib/SFML, then use "-I/usr/include/SFML/" and "-L/usr/lib/SFML/" and some -l's in the g++ command.  In the end none of my guesses came close to getting g++ to realize these libraries existed, much less produce an actual executable.

Out of my dozens of failed combinations of file placement and command line arguments, the errors I typically got were either: 1) an "undefined reference" to every single SFML function in the sample main.cpp, 2) "/usr/bin/ld: cannot find -lsfml-graphics" or any of the other libraries I tried including with -l, or 3) several "undefined reference"s to glew macros (that was a really weird one...)

So how exactly are you supposed to compile an SFML program on linux?  Where am I supposed to put all of the files in the "SDK"?  Should I only move the .hpps and .so's?  Do I need to treat the .so, .so.2 and .so.2.1 libs differently in some way?  Should I be trying to preserve the placement of certain subdirectories?  Should I be doing anything with the lone .cmake file or the .pkg files?  What should my actual g++ command look like?  The tutorial just doesn't tell me any of this.

Incidentally I've been using SFML on Windows for weeks now and it's been almost effortless there.  I've also used gcc/g++ from the command line before in Cygwin, though I've never had to figure out how to make them link with a library they didn't automagically know about already.
« Last Edit: August 04, 2013, 06:07:05 pm by Ixrec »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #1 on: August 04, 2013, 06:17:38 pm »
Quote
put the contents of SFML-2.1/include/SFML into /usr/include/SFML and the contents of SFML-2.1/lib/ into /usr/lib/SFML, then use "-I/usr/include/SFML/" and "-L/usr/lib/SFML/" and some -l's in the g++ command
Looks good -- although /usr/local or /home/... are recommended for user libraries (/usr is reserved for what the OS installs itself).

Now what does your command line look like, and what are the corresponding error messages?

Quote
So how exactly are you supposed to compile an SFML program on linux?  Where am I supposed to put all of the files in the "SDK"?  Should I only move the .hpps and .so's?  Do I need to treat the .so, .so.2 and .so.2.1 libs differently in some way?  Should I be trying to preserve the placement of certain subdirectories?  Should I be doing anything with the lone .cmake file or the .pkg files?  What should my actual g++ command look like?  The tutorial just doesn't tell me any of this.
The tutorial says nothing because there's nothing specific to say here.

Just put SFML where you want, as long as you tell g++ where it is with -I and -L. Then link the SFML libraries like any other library (-lsfml-xxx). Use the .cmake file if you use CMake, use the .pkg file if you use pkg-config. Ignore them if you don't know what they are. That's all.
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #2 on: August 04, 2013, 07:42:35 pm »
Okay, cleaned up the mess I made earlier, and based on what you've said I think this test is fairly close to how it's supposed to work.

In my home directory is a folder called "code" that contains the "SFML-2.1" folder (the SDK thing, unaltered) and the sample main.cpp.  This is what happens:

Quote
ixrec@ubuntu:~$ cd code
ixrec@ubuntu:~/code$ g++ -I~/code/SFML-2.1/include/SFML/ -L~/code/SFML-2.1/lib/ -lsfml-system -lsfml-window -lsfml-graphics main.cpp
/usr/bin/ld: cannot find -lsfml-system
/usr/bin/ld: cannot find -lsfml-window
/usr/bin/ld: cannot find -lsfml-graphics
collect2: ld returned 1 exit status
ixrec@ubuntu:~/code$

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #3 on: August 04, 2013, 08:42:50 pm »
Are you sure that "~" is correctly interpreted in this context? You should try with the full path.
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #4 on: August 04, 2013, 08:47:54 pm »
Damn, that one sounded like it might be it.  Sadly, no change:

g++ -I/home/Ixrec/code/SFML-2.1/include/SFML/ -L/home/Ixrec/code/SFML-2.1/lib/ -lsfml-system -lsfml-window -lsfml-graphics main.cpp

/usr/bin/ld: cannot find -lsfml-system
/usr/bin/ld: cannot find -lsfml-window
/usr/bin/ld: cannot find -lsfml-graphics
collect2: ld returned 1 exit status

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #5 on: August 04, 2013, 10:03:23 pm »
You're supposed to put the file(s) to compile before the libraries to link on the command line, but it may not solve your problem either.
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #6 on: August 04, 2013, 11:07:53 pm »
Yeah, that also makes no difference.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #7 on: August 04, 2013, 11:40:24 pm »
I tried a few other locations and for whatever reason g++ can find the libs when I put them in /lib/SFML and use -L/lib/SFML.  Go figure.

But now I have a completely different set of errors!  So here's what happened this time:

g++ main.cpp -I/home/Ixrec/code/SFML-2.1/include/SFML -L/lib/SFML -lsfml-system -lsfml-window -lsfml-graphics

/usr/bin/ld: warning: libGLEW.so.1.7, needed by /lib/SFML/libsfml-graphics.so, not found (try using -rpath or -rpath-link)
/lib/SFML/libsfml-graphics.so: undefined reference to '__glewUniform1fARB'
/lib/SFML/libsfml-graphics.so: undefined reference to '__GLEW_ARB_shader_objects'
...

There's a couple dozen of these undefined references to what I assume are glew functions or macros.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #8 on: August 05, 2013, 12:23:25 am »
This won't solve your new problem, but shouldn't your include flag be  "-I/home/Ixrec/code/SFML-2.1/include" ?

As far as your GLEW issues go, you just need to download GLEW from your package manager and that should fix that issue.
DSFML - SFML for the D Programming Language.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #9 on: August 05, 2013, 11:08:12 am »
According to the Ubuntu Software Center I already had runtime environments for glew 1.5 and 1.6, but there's nothing glew-related with 1.7 on it.  All I can add are "utilities" and "development environment"s for 1.5 and 1.6.

Does this mean I have to compile glew 1.7 from sources?

The include flag change didn't do anything, but I'll keep that in mind when I'm fiddling with it in the future.  I figured I'd have to tack the "SFML" part on the end because I'm under the impression g++ isn't going to automatically check subfolders for me (considering how bad it is at finding libs even when I tell it the exact directory), and all the headers are in include/SFML, not in include/ itself.

*edit* Made an extremely short-lived attempt to compile the latest 1.10 sources:

Quote
ixrec@ubuntu:~/code/glew-1.10.0$ configure
configure: command not found

ixrec@ubuntu:~/code/glew-1.10.0$ ./configure
bash: ./configure: No such file or directory

ixrec@ubuntu:~/code/glew-1.10.0$ make
cc -DGLEW_NO_GLU -02 -Wall -W -Iinclude -fPIC -o tmp/linux/default/shared/glew.o -c src/glew.c
In file included from src/glew.c:37:0:
include/GL/glxew:97:22: fatal error: X11/Xlib.h: No such file or directory
compilation terminated
make: *** [tmp/linux/default/shared/glew.o] Error 1
« Last Edit: August 05, 2013, 11:16:17 am by Ixrec »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #10 on: August 05, 2013, 11:31:14 am »
Quote
According to the Ubuntu Software Center I already had runtime environments for glew 1.5 and 1.6, but there's nothing glew-related with 1.7 on it.  All I can add are "utilities" and "development environment"s for 1.5 and 1.6.
This is very annoying, and is a consequence of how GLEW manages its version numbers. There's nothing I can do; this issue will be solved when official Linux repositories include SFML packages directly.

Quote
Does this mean I have to compile glew 1.7 from sources?
You should rather recompile SFML.

Quote
I figured I'd have to tack the "SFML" part on the end because I'm under the impression g++ isn't going to automatically check subfolders for me (considering how bad it is at finding libs even when I tell it the exact directory), and all the headers are in include/SFML, not in include/ itself.
What you're going to include, and thus what the compiler will try to locate in its search paths, is "SFML/xxx.hpp", not "xxx.hpp". So you must give the path to "SFML/xxx.hpp", and this path is "<sfml-install-path>/include", not "<sfml-install-path>/include/SFML".

Quote
fatal error: X11/Xlib.h: No such file or directory
For the record, this means that you need the development files of Xlib in order to compile GLEW.
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #11 on: August 05, 2013, 11:38:02 am »
Okay, in that case I'll try compiling SFML.

If it matters, Ubuntu Software Center did have a very strangely named SFML package, but I don't think it was 2.0+.

Barlog

  • Guest
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #12 on: August 05, 2013, 11:44:37 am »
Greetings.

To compile from source try following steps.

0. Preparing dev-env and tools
Install "release" and dev versions of following libraries, as SFML is dependent in them:
pthread, opengl, xlib, xrandr, freetype, glew, jpeg, sndfile, openal

Open terminal (Win+T) and run following command (warn could be typos)
sudo apt-get install libpthread-stubs0 libpthread-stubs0-dev libgl1-mesa-glx libgl1-mesa-dri libgl1-mesa-dev libx11-6 libx11-dev libxrandr2 libxrandr-dev libfreetype6 libfreetype6-dev libglew1.8 libglew-dev libjpeg-turbo8 libjpeg-turbo8-dev libsndfile1 libsndfile1-dev libopenal1 libopenal-dev cmake cmake-qt-gui git

1. Getting source code from git
In terminal window run following command:
mkdir -p ~/dev/sfml && cd ~/dev/sfml && git init && git pull https://github.com/SFML/SFML && mkdir build && mkdir build-d && cmake-gui

The source code will be located in your "~/dev/sfml" folder.

2. Making release version of SFML
In cmake gui window write "~/dev/sfml" to "Where is source code" input field.
Write "~/dev/sfml/build" to "Where to build the binaries" input field.
Press "Configure" button, select "Unix makefiles" and "Use default native compilers". Wait until process is finished.
Put tick mark to "SFML_INSTALL_PKGCONFIG_FILES" and press "Configure" again after that press "Generate".

2. Making debug version of SFML
In cmake gui window write "~/dev/sfml" to "Where is source code" input field.
Write "~/dev/sfml/build-d" to "Where to build the binaries" input field.
Change "CMAKE_BUILD_TYPE" to "Debug", put tick mark to "SFML_INSTALL_PKGCONFIG_FILES" and press "Configure" again then press "Generate" button.
Close cmake gui window.

3. Compiling and installing SFML release and debug versions. SFML will be installed in standard location
In terminal window run following command lines:

For release version of SFML run
cd ~/dev/sfml/build && sudo make all && sudo make install

For debug version run
cd ~/dev/sfml/build-d && sudo make all && sudo make install

For next steps refer to this tutorials
http://www.sfml-dev.org/tutorials/2.1/start-linux.php
http://www.sfml-dev.org/tutorials/2.1/start-cb.php

Hope this helps. :)

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #13 on: August 05, 2013, 12:25:25 pm »
...as it turns out, on Linux compiling from source is A LOT easier than using prebuilt libraries.  Either that or CMake is magic.

I got it to work almost on the first try with barely any effort.  For me the tutorial on compiling with CMake had everything I needed except the exact list of packages, which I found in this thread (before Tirion Helkaraxe posted; sorry you went to all that trouble).

Dynamic linking gave me the usual library not found errors even though the CMake option to install shared libs was on, so that's still puzzling, but static is what I wanted anyway so that's fine.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: I cannot figure out how to compile the sample SFML program in Linux
« Reply #14 on: August 05, 2013, 12:55:02 pm »
Quote
...as it turns out, on Linux compiling from source is A LOT easier than using prebuilt libraries.  Either that or CMake is magic.
Both ;)
Laurent Gomila - SFML developer