SFML community forums

Help => General => Topic started by: Xylankant on June 28, 2008, 01:00:49 am

Title: [Solved] static linking in linux?
Post by: Xylankant on June 28, 2008, 01:00:49 am
Hey folks!

I've just stumbled upon a problem using SFML under Linux (as Cross Compiling binaries for Linux is quite non-trivial under WinXP ^^ ).

Problem is: I can't figure out a way of statically linking the libraries.

Code: [Select]
g++ -c main.cpp
g++ -o main main.o -static lsfml-system

will give me an error saying
/usr/bin/ld: cannot find lsfml-system

When I try compiling without the -static option, everything works fine, however I'd have a dynamic link

I have as well tried -Wl,-static and -Wl,-Bstatic, all's the same result...

System is Ubuntu 8.04
SFML is 1.3

Is there a way to solve this problem?
Title: [Solved] static linking in linux?
Post by: Wizzard on June 28, 2008, 05:19:38 am
The way it works in MinGW is you just links the libraries that have "-s" in their name. You do not need to use "-static".

EDIT: Does a dynamically linked version of SFML even exist for Linux?

Have you tried just doing this?

Code: [Select]
g++ -c main.cpp
g++ -o main main.o -lsfml-system


The error "/usr/bin/ld: cannot find lsfml-system" makes me think you don't have the correct syntax for g++.

After a little time on google, I found examples of people using syntax like this to statically link libraries:

Code: [Select]
-static-libsfml-system
Title: [Solved] static linking in linux?
Post by: Xylankant on June 28, 2008, 09:59:36 am
Quote from: "Wizzard"

Have you tried just doing this?

Code: [Select]
g++ -c main.cpp
g++ -o main main.o -lsfml-system


The error "/usr/bin/ld: cannot find lsfml-system" makes me think you don't have the correct syntax for g++.

Yap, I wrote above that, without the -static option, I'm fine with compiling ;)

Quote from: "Wizzard"

After a little time on google, I found examples of people using syntax like this to statically link libraries:

Code: [Select]
-static-libsfml-system

thanks, I'll try it and report on that!
Title: [Solved] static linking in linux?
Post by: Xylankant on June 28, 2008, 10:07:36 am
Ok, that doesn't work :)

But thanks anyway...

P.S.: Syntax doesn't seem to matter that much, as for what I found out was people writing the same options down to different positions, doing the same, however, compiling with
Code: [Select]
g++ -c [filename] [options]
g++ -o [output file] [input file] [options]
should always work...and it does with sfml, as well, when not linking statically
Title: [Solved] static linking in linux?
Post by: Laurent on June 28, 2008, 10:10:37 am
SFML libraries under Linux are dynamic only, the static ones are not provided.
Title: [Solved] static linking in linux?
Post by: Xylankant on June 28, 2008, 10:17:48 am
Quote from: "Laurent"
SFML libraries under Linux are dynamic only, the static ones are not provided.

OK, thank you.
Good to known, now I can stop searching a way to link statically :)

So, what to do when "shipping" my program to a friend of mine, who doesn't have sfml installed to his system?
Does he have to install sfml, or is shipping the -lsfml-xxx.so.1 right with my program enough?
Title: [Solved] static linking in linux?
Post by: Laurent on June 28, 2008, 10:44:01 am
The best solution is to install SFML on your friend's computer (this can be done by a script provided with your program), which is just copying the libraries and creating the proper symbolic links.
Title: [Solved] static linking in linux?
Post by: Xylankant on June 28, 2008, 10:50:27 am
Ok, thank you very much, Laurent.

I have to admitt, I don't known how to do that right now, but I'm going to find out (I'm new to Linux programming ^^).
So far, my friend is willing to install sfml by himself (good luck for me ;) )
Title: [Solved] static linking in linux?
Post by: Laurent on June 28, 2008, 10:58:44 am
Installing SFML is just copying the libraries (all the *.so.1) to either /usr/lib or /usr/local/lib, and creating the symbolic links libsfml-xxx-.so pointing to libsfml-xxx-.so.1.

Take a look at the "install" target of the makefiles for the corresponding commands.
Title: [Solved] static linking in linux?
Post by: Xylankant on June 28, 2008, 11:01:28 am
Thanks again, I'm going to work through that!
Title: [Solved] static linking in linux?
Post by: Xp on February 17, 2011, 02:12:12 pm
Quote from: "Laurent"
Installing SFML is just copying the libraries (all the *.so.1) to either /usr/lib or /usr/local/lib, and creating the symbolic links libsfml-xxx-.so pointing to libsfml-xxx-.so.1.

Take a look at the "install" target of the makefiles for the corresponding commands.


sorry for ressurecting an old thread but I have a question on this...

what about if I build it in my pc and want to test it in University pcs with no root acess? (not possible to enter in usr folder)

impossible?
Title: [Solved] static linking in linux?
Post by: Laurent on February 17, 2011, 02:48:19 pm
Yes, install it wherever you want (like /home/you/sfml) and setup your compiler, linker and library loader to know about this particular path.
Title: [Solved] static linking in linux?
Post by: Xp on June 09, 2011, 10:00:38 pm
Quote from: "Laurent"
and setup your compiler, linker and library loader to know about this particular path.


that would require root access right?
Title: [Solved] static linking in linux?
Post by: Laurent on June 09, 2011, 10:24:22 pm
Nop.