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

Author Topic: Static Linking for SFML 2.0 RC on Linux  (Read 5458 times)

0 Members and 1 Guest are viewing this topic.

rbkza

  • Newbie
  • *
  • Posts: 4
    • View Profile
Static Linking for SFML 2.0 RC on Linux
« on: April 02, 2013, 03:35:31 pm »
I'm running 64-bit Ubuntu, and I've managed to get my code to compile and run, but only by dynamically linking against the SFML libraries at runtime (by setting the environmental variable LD_LIBRARY_PATH to my SFML lib directory).

However, I'd like to statically link SFML into my application, which is where I'm running into problems. I get the following errors:

Code: [Select]
/usr/bin/ld: cannot find -lsfml-graphics-s
/usr/bin/ld: cannot find -lsfml-window-s
/usr/bin/ld: cannot find -lsfml-system-s

However, if I leave off the -s suffix, I don't have any problems, but I then need to set the LD_LIBRARY_PATH variable at runtime, which is what I'm trying to avoid. So how do I link the SFML libraries into my application statically? I've looked into my SFML lib directory, and I don't see and libraries matching the -s suffix. Does this mean that the current version of SFML 2.0 RC does not come with static libraries? Or do static linking and dynamic linking use the same libraries, and I'm just missing something obvious?

The version of SFML I'm using is the C++ version 2.0 RC available from this link on the downloads page. 

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Static Linking for SFML 2.0 RC on Linux
« Reply #1 on: April 02, 2013, 03:51:53 pm »
On Linux one often tries to avoid statically linking, since the dynamic way is more practical, that's also why the official RC release doesn't ship with static libraries for Linux.
If you want static libraries, you'll have to compile SFML on your own, which is what I'd suggest anyways, since the RC is already quite old.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

rbkza

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Static Linking for SFML 2.0 RC on Linux
« Reply #2 on: April 02, 2013, 04:12:51 pm »
Ah, fantastic, thank you!

Why would you say it's impractical to link statically? Surely dynamic linking is just another thing that could go wrong when distributing the binary? A separate run script needs to be created to first export the LD_LIBRARY_PATH variable before executing the binary, or is there another way?

Haze

  • Full Member
  • ***
  • Posts: 201
    • View Profile
    • Github Profile
Re: Static Linking for SFML 2.0 RC on Linux
« Reply #3 on: April 03, 2013, 07:53:54 pm »
Why would you say it's impractical to link statically? Surely dynamic linking is just another thing that could go wrong when distributing the binary?
There's nothing wrong with static linking, but it's simply not the "linux way", and using the system shared libraries (installed from your distribution packages) is regarded as a better practice.
Libraries are usually built for shared linking, so if you intend to static link, you'll probably have to compile them yourself, which can be a serious pain.

A separate run script needs to be created to first export the LD_LIBRARY_PATH variable before executing the binary, or is there another way?
Yes, this is very easy and seems to be the more popular way for distributing stand-alone release of your project.
Just copy the .so files to a sub directory, and provide a shell launcher.
You can see an example of mine here.

rbkza

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Static Linking for SFML 2.0 RC on Linux
« Reply #4 on: April 04, 2013, 11:20:45 pm »
There's nothing wrong with static linking, but it's simply not the "linux way", and using the system shared libraries (installed from your distribution packages) is regarded as a better practice.
Fair enough, but I'm only really interested in statically linking the SFML libraries, not all of its dependencies. Besides, I don't see SFML 2.0 in the Ubuntu repos yet, so I'd have to bundle the SFML shared object files with my project anyway.

Libraries are usually built for shared linking, so if you intend to static link, you'll probably have to compile them yourself, which can be a serious pain.
Good point. Although I've managed to compile and use the SFML shared libraries without much trouble, I haven't had any luck getting the static libraries to work. During the linking of my own project with the SFML libraries, I'm presented with undefined references to pthread_getspecific. Could this be a bug somewhere in SFML, or is it more likely that there's something wrong on my side? I fairly certain that I do have the correct development headers package installed, besides, it's only the static libraries that are giving problems, not the shared libraries.

Yes, this is very easy and seems to be the more popular way for distributing stand-alone release of your project.
Just copy the .so files to a sub directory, and provide a shell launcher.
You can see an example of mine here.
Great, thank you :)

 

anything