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

Author Topic: SFML 2.0 building with cmake almost working  (Read 4829 times)

0 Members and 1 Guest are viewing this topic.

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
SFML 2.0 building with cmake almost working
« on: November 22, 2011, 12:10:59 am »
Hi,
I recently started to dig into SFML and I was happy to see the 2.0 version is cmake-enabled. I installed the required packages (debian squeeze x64)
Code: [Select]
libglew1.5-dev libxrandr-dev libfreetype6-dev libjpeg8-dev libsndfile1-dev libopenal-dev libpthread-stubs0-dev libxrandr2-dbg libx11-dev doxygen
and built it (with examples and docs) according to the example. Now the thing is, when I build it with shared libs chosen it works allright (or so it seems), but when I choose static libs I get an error building the OpenGL example.

Code: [Select]
Scanning dependencies of target opengl
[ 85%] Building CXX object examples/opengl/CMakeFiles/opengl.dir/OpenGL.cpp.o
Linking CXX executable opengl
../../lib/libsfml-graphics-s.a(Font.cpp.o): In function `sf::Font::SetCurrentSize(unsigned int) const':
Font.cpp:(.text+0x181): undefined reference to `FT_Set_Pixel_Sizes'
../../lib/libsfml-graphics-s.a(Font.cpp.o): In function `sf::Font::GetLineSpacing(unsigned int) const':
Font.cpp:(.text+0x441): undefined reference to `FT_Set_Pixel_Sizes'
../../lib/libsfml-graphics-s.a(Font.cpp.o): In function `sf::Font::GetKerning(unsigned int, unsigned int, unsigned int) const':
Font.cpp:(.text+0x8d7): undefined reference to `FT_Set_Pixel_Sizes'
Font.cpp:(.text+0x8e5): undefined reference to `FT_Get_Char_Index'
Font.cpp:(.text+0x8f2): undefined reference to `FT_Get_Char_Index'
Font.cpp:(.text+0x903): undefined reference to `FT_Get_Kerning'
../../lib/libsfml-graphics-s.a(Font.cpp.o): In function `sf::Font::Cleanup()':


...and a lot more lines like those, the full transcript here. When I try to build other example targets individually they fail similarly.

However if I choose to build with shared libs, it looks like it finishes allright, but when I try to launch any of the example executables I get a shared library loading error:

Code: [Select]
nietaki@logical:~/zpp/SFMLbuild/examples/pong$ ./pong
./pong: error while loading shared libraries: libsfml-audio.so.2: cannot open shared object file: No such file or directory
nietaki@logical:~/zpp/SFMLbuild/examples/sockets$ ./sockets
./sockets: error while loading shared libraries: libsfml-network.so.2: cannot open shared object file: No such file or directory


Am I doing something wrong? Or is it the charm of the pre-release version ;)? I've seen Nexus stating he's using it already...

PS. This is also my "hello" post, I am now checking out SFML and if I end up choosing it over SDL for my BS project you'll end up stuck with me for a few months ;)

edit: I tried it on my x86 netbook just to make sure and the results were exactly the same, I might try it under windows tommorow but if I don't get this solved I won't be able to get the platform independence my team was hoping for ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 building with cmake almost working
« Reply #1 on: November 22, 2011, 07:39:49 am »
Static libs: there's no link step when compiling static libraries, so you need to link every dependency to your final app (FreeType, GLEW, libjpg, libsndfile, ...).
On Windows there's a trick so that it's done automatically; on other OSes static link doesn't make sense, they are so good at managing shared libs -- so don't do it ;)

Shared libs: http://www.sfml-dev.org/forum/viewtopic.php?p=41947#41947

Note that these issues are not directly related to SFML, it would be the same with any other library. So it's always good to remember this stuff ;)
Laurent Gomila - SFML developer

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
SFML 2.0 building with cmake almost working
« Reply #2 on: November 22, 2011, 11:48:15 am »
Thanks for the quick response, Laurent, worked like a charm.

For people in the future googling this problem:

after informing ld about the directory where the libraries were created (either /path/to/your/SFML_build/lib or i.e. /usr/local/lib if you already run 'make install'), by running:

Code: [Select]
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib

or (even better) by using ldconfig as per one of the tutorials.

So it's working, I'm going to be writing some test code in the next week, but I can already tell I like the SFML api and the community :)

Disregard the text below, it's just for future reference ;)
One more note: if you're doing an "out-of-source build" (the source directory is different from the build directory), some of the examples won't work unless you copy the resources directory from the corresponding source directory and run the example from it's own directory.

PS. Please don't take it as me being a smartass (I'm just a begginer when it comes to compiled languages) or telling you how to do the great job you're doing better, but making the examples work more out-of-the-box (by e.g. using file(COPY srcDir DESTINATION destination) in the CMakeLists.txt for the resources dirs if it's at all possible) before the library release might win you the hearts of the newbies. Would it be to petty for me to submit it in the SFML issue tracker as a feature request and/or even propose a patch?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 building with cmake almost working
« Reply #3 on: November 22, 2011, 11:56:11 am »
In fact you're not supposed to do anything in the build tree, you must install SFML (make install) after compiling it. Then you'll get a clean release tree, the same that you'd get by downloading a public release or installing SFML from your Linux repo -- both options are of course not available until SFML 2 is released, that's just for the example ;)
Laurent Gomila - SFML developer

nietaki

  • Newbie
  • *
  • Posts: 30
    • View Profile
    • http://almost-done.net
SFML 2.0 building with cmake almost working
« Reply #4 on: November 22, 2011, 12:00:09 pm »
yeah, I just had a closer look at the what the make install wrote, let me take back half the things I said ;)