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

Author Topic: Linking in Linux  (Read 7524 times)

0 Members and 1 Guest are viewing this topic.

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Linking in Linux
« on: August 15, 2013, 07:42:21 am »
Hey everyone.  I've been using SFML on Windows for the past 6 months, but I've been using CMake for my build system so that I could ensure that I could build it in Linux at least.  So, I've hit a milestone in my engine and I want to ensure that everything works in Linux as well, because I would like to be able to release Windows/Linux at least.  Anyway, I've fixed all the issues with my code, and I've even got the .a library linking, but unfortunately g++ is having issues linking the libraries linked to by SFML (for instance x11).  I build SFML with these directions:

http://sfmlcoder.wordpress.com/2011/08/16/building-sfml-2-0-with-make-for-gcc/

I added all of the libraries needed, but for whatever reason g++ isn't finding them when it goes to link my application.  Anyone have any ideas on how to possibly resolve this? 

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Linking in Linux
« Reply #1 on: August 15, 2013, 08:17:24 am »
Please post the error messages ld produces. The build commands would also be helpful (make VERBOSE=1).

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Linking in Linux
« Reply #2 on: August 16, 2013, 01:34:24 am »
Here's the tail end of the linking errors:

Quote
Texture.cpp:(.text+0x18be): undefined reference to `glGetTexImage'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(Texture.cpp.o): In function `sf::Texture::operator=(sf::Texture const&)':
Texture.cpp:(.text+0x1bec): undefined reference to `glDeleteTextures'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(TextureSaver.cpp.o): In function `sf::priv::TextureSaver::TextureSaver()':
TextureSaver.cpp:(.text+0x13): undefined reference to `glGetIntegerv'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(TextureSaver.cpp.o): In function `sf::priv::TextureSaver::~TextureSaver()':
TextureSaver.cpp:(.text+0x35): undefined reference to `glBindTexture'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(GLCheck.cpp.o): In function `sf::priv::glCheckError(char const*, unsigned int)':
GLCheck.cpp:(.text+0x34): undefined reference to `glGetError'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(GLCheck.cpp.o): In function `sf::priv::ensureGlewInit()':

The funny thing is, I specifically link to the glew.a library from the extlibs directory.  Any suggestion?  I didn't just sudo apt-get install sfml-dev because I think I read that 2.1 isn't there yet, and I'd like to be working off of 2.1.  Any help here would be greatly appreciated.

Jebbs

  • Sr. Member
  • ****
  • Posts: 358
  • DSFML Developer
    • View Profile
    • Email
Re: Linking in Linux
« Reply #3 on: August 16, 2013, 02:54:03 am »
Here's the tail end of the linking errors:

Quote
Texture.cpp:(.text+0x18be): undefined reference to `glGetTexImage'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(Texture.cpp.o): In function `sf::Texture::operator=(sf::Texture const&)':
Texture.cpp:(.text+0x1bec): undefined reference to `glDeleteTextures'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(TextureSaver.cpp.o): In function `sf::priv::TextureSaver::TextureSaver()':
TextureSaver.cpp:(.text+0x13): undefined reference to `glGetIntegerv'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(TextureSaver.cpp.o): In function `sf::priv::TextureSaver::~TextureSaver()':
TextureSaver.cpp:(.text+0x35): undefined reference to `glBindTexture'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(GLCheck.cpp.o): In function `sf::priv::glCheckError(char const*, unsigned int)':
GLCheck.cpp:(.text+0x34): undefined reference to `glGetError'
/home/hatfarm/SFML-2.1//lib/libsfml-graphics-s.a(GLCheck.cpp.o): In function `sf::priv::ensureGlewInit()':

The funny thing is, I specifically link to the glew.a library from the extlibs directory.  Any suggestion?  I didn't just sudo apt-get install sfml-dev because I think I read that 2.1 isn't there yet, and I'd like to be working off of 2.1.  Any help here would be greatly appreciated.

Those are OpenGL functions, not Glew ones. Looks like you aren't linking to OpenGL.

Doesn't linking with the graphics module automatically link your program to OpenGL though?
DSFML - SFML for the D Programming Language.

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Re: Linking in Linux
« Reply #4 on: August 16, 2013, 03:26:05 am »
Doesn't linking with the graphics module automatically link your program to OpenGL though?
Not if he's linking statically.
I use the latest build of SFML2

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Linking in Linux
« Reply #5 on: August 16, 2013, 03:33:56 am »
I am linking statically, when I tried to use the so.2.1 files, it said that it didn't have a build option (or something like that) for those libraries.  How do I go about linking OpenGL then?  Would I be better off using the dynamic libraries?

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
Re: Linking in Linux
« Reply #6 on: August 16, 2013, 08:29:47 am »
-lGL

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Linking in Linux
« Reply #7 on: August 16, 2013, 04:55:06 pm »
So, it's not linking any of the libraries that are needed by SFML.  Is there anywhere I can find the "-l"s that I need to build all of it.  Is there any easy way to do that in CMake?  Thanks for all your help.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Linking in Linux
« Reply #8 on: August 16, 2013, 05:22:03 pm »
If you're linking things statically, you'll have to link against SFML and all its dependencies. You can find a list of them here.
And no there isn't really an easy way to do it (afaik).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Linking in Linux
« Reply #9 on: August 16, 2013, 05:40:14 pm »
For me, using CMake to build my program (not just SFML) magically solved all of these linking problems. All I had to do was make my program into one of SFML's example programs by modifying the relevant CMake files. It was easy to guess how since those files are so simple.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: Linking in Linux
« Reply #10 on: August 16, 2013, 06:06:31 pm »
For me, using CMake to build my program (not just SFML) magically solved all of these linking problems.
Are you linking statically as well? ;)
Dynamic linkage will be much easier, yes.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Linking in Linux
« Reply #11 on: August 17, 2013, 01:02:02 am »
Yes mine's all static (unless you count the audio libraries).

hatfarm

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Linking in Linux
« Reply #12 on: August 17, 2013, 11:11:31 pm »
The problem I'm having is that I already wrote my CMake files and didn't have any issues with Windows, but now with Linux I have to link all of these libraries separately.  I've looked through the SFML CMake files and I can't find where the variables are actually defined.  There is, for instance, the "OPENGL_INCLUDE_DIR" but I cannot find where that is defined.  I actually wrote a python script to search for that in all .txt files under the main SFML directory(and subdirectories) and was unable to find it.  Any recommendations?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linking in Linux
« Reply #13 on: August 17, 2013, 11:19:46 pm »
This kind of variables are defined by the find_package(XXX) calls.
Laurent Gomila - SFML developer

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Linking in Linux
« Reply #14 on: August 17, 2013, 11:30:33 pm »
That's why I made my program pretend to be one of SFML's examples.  Just go into the examples folder, modify the CMake file there which essentially just lists subfolders (after making a new subfolder for your program), then look at the CMake file that each example program's subfolder has and make a version of it for your program.  The files are pretty self-explanatory.

I have no idea if this was the optimal approach but it was very quick and easy and it hasn't broken for me yet.