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

Author Topic: [Solved] static linking in linux?  (Read 6767 times)

0 Members and 1 Guest are viewing this topic.

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
[Solved] static linking in linux?
« 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?

Wizzard

  • Full Member
  • ***
  • Posts: 213
    • View Profile
[Solved] static linking in linux?
« Reply #1 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

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
[Solved] static linking in linux?
« Reply #2 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!

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
[Solved] static linking in linux?
« Reply #3 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] static linking in linux?
« Reply #4 on: June 28, 2008, 10:10:37 am »
SFML libraries under Linux are dynamic only, the static ones are not provided.
Laurent Gomila - SFML developer

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
[Solved] static linking in linux?
« Reply #5 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] static linking in linux?
« Reply #6 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.
Laurent Gomila - SFML developer

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
[Solved] static linking in linux?
« Reply #7 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 ;) )

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] static linking in linux?
« Reply #8 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.
Laurent Gomila - SFML developer

Xylankant

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • http://xylankant.xy.funpic.de
[Solved] static linking in linux?
« Reply #9 on: June 28, 2008, 11:01:28 am »
Thanks again, I'm going to work through that!

Xp

  • Newbie
  • *
  • Posts: 13
    • View Profile
[Solved] static linking in linux?
« Reply #10 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] static linking in linux?
« Reply #11 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.
Laurent Gomila - SFML developer

Xp

  • Newbie
  • *
  • Posts: 13
    • View Profile
[Solved] static linking in linux?
« Reply #12 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[Solved] static linking in linux?
« Reply #13 on: June 09, 2011, 10:24:22 pm »
Nop.
Laurent Gomila - SFML developer