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

Author Topic: Linux , how to link static?  (Read 6144 times)

0 Members and 1 Guest are viewing this topic.

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Linux , how to link static?
« on: July 15, 2013, 07:15:08 pm »
Hello all,

i have create static libarys for Linux by this Tutorial in Cmake: http://sfmlcoder.wordpress.com/2011/08/16/building-sfml-2-0-with-make-for-gcc/ Now i have compiled my test app with this tutorial: http://www.sfml-dev.org/tutorials/2.0/start-linux.php

My Question:

Other Poeple cant start my compiled sfml-app.  I think, its because this ways does not use the static linked libarys. But how can i make that?

Thank you for help :) !
« Last Edit: July 15, 2013, 08:21:13 pm by Chi »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Ubuntu/Code::Blocks - compiler errors
« Reply #1 on: July 15, 2013, 08:17:15 pm »
You must link the dependencies of SFML. When you create a static library no linking is done, it's left to the final binary.
Laurent Gomila - SFML developer

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Ubuntu/Code::Blocks - compiler errors
« Reply #2 on: July 15, 2013, 08:22:56 pm »
You must link the dependencies of SFML. When you create a static library no linking is done, it's left to the final binary.

Hello Laurent, thanks for your fast answer.
I want to choose now the way without an IDE. It works. But i have another Problem, that other poeple using Linux cant start my sfml-app. (I have edit my first post and describe it).  How can use the static libarys for compiling?

best regards

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linux , how to link static?
« Reply #3 on: July 15, 2013, 08:30:28 pm »
Quote
other poeple using Linux cant start my sfml-app
More details would be welcome.
Laurent Gomila - SFML developer

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Linux , how to link static?
« Reply #4 on: July 15, 2013, 08:46:50 pm »
More details would be welcome.

i compiling like this:

Code: [Select]
g++ -c test.cpp -I /home/brause/dev/include
g++ test.o -o sfml-app -L /home/brause/dev/lib -lsfml-graphics -lsfml-window -lsfml-system

when they start ./sfml-app , they get the message:

"command not found".

but i can start the sfml-app by  ./sfml-app or also doppelclick. This:

Code: [Select]
export LD_LIBRARY_PATH=<sfml-install-path>/lib && ./sfml-app
is not need, dont know why.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linux , how to link static?
« Reply #5 on: July 15, 2013, 08:50:22 pm »
I don't know, sorry. They probably do something wrong but I don't know what.
Laurent Gomila - SFML developer

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Linux , how to link static?
« Reply #6 on: July 15, 2013, 08:55:43 pm »
Why they do something wrong? I Think i dont have compiled with the static libarys?
Because on the website you write this:

Quote
If SFML is not installed in a standard path, you need to tell the library loader where to find the SFML libraries first:
export LD_LIBRARY_PATH=<sfml-install-path>/lib && ./sfml-app

Of course they didnt have installed sfml.  I want to compile it like that they dont need to install :o ?

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Linux , how to link static?
« Reply #7 on: July 15, 2013, 09:09:35 pm »
ok - i try to ask on another way.

How can i choose when i compilng:

g++ test.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

wich libarys are used  static/shared/debug/release ?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Linux , how to link static?
« Reply #8 on: July 15, 2013, 09:50:20 pm »
Quote
Why they do something wrong?
I said "probably". Because it works for you and not for them, and because of the error message too. "Command not found" means that what they type doesn't exist; a missing dependency would trigger another error ("Failed to find shared library xxx.so" or something).

Quote
How can i choose when i compilng:

g++ test.o -o sfml-app -lsfml-graphics -lsfml-window -lsfml-system

wich libarys are used  static/shared/debug/release ?
Everything is explained in the "Getting started" tutorial.
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10835
    • View Profile
    • development blog
    • Email
Re: Linux , how to link static?
« Reply #9 on: July 15, 2013, 10:16:45 pm »
when they start ./sfml-app , they get the message:

"command not found".
They need to make sure, that the sfml-app has the correct permissions, especially the one for execution.

Btw. it's still recommended to link shared on Linux and simply provide the needed libraries in a separated directory and then create a shell script that adds the path of the library to LD_LIBRARY_PATH. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

cpolymeris

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
    • Email
Re: Linux , how to link static?
« Reply #10 on: July 15, 2013, 10:29:07 pm »
`gcc -static ...` tries to link everything statically... which is baaaad. So distros go out of their way to make it imposible.

If you want to link some stuff statically, you should just link their .o files, from the SFML compilation. Or, bettter, use libtool to make a libsfml-*-.la, which is actually just a description of what to link, and "link" that.

EDIT: Just to make this clear, it would be e.g.:
gcc -lstdc++ -o my-app my-app.cc smfl-source-dir/Display.o smfl-source-dir/Mouse.o...
If you add -lsfml-* in there it will still try to dynamically link, of course.
« Last Edit: July 15, 2013, 10:33:56 pm by cpolymeris »

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Linux , how to link static?
« Reply #11 on: July 15, 2013, 10:58:06 pm »
Thank you for all your answers! I try to figure out your suggestions about sharing shared linked binarys. But there is one thing i still not understand.

Laurent wrote its explained in the getting started tutorial. Maybe i dont understand what he write their, but iam still confused about the compiler command:

-lsfml-graphics -lsfml-window -lsfml-system

how the g++ knows about wich libarys is used?  Or better say: How i know wich libary is used? What is happening with this command? Because i have create 4 libarys for static/shared  debug/release. My folder /usr/local/lib$ ls looks like this:

Quote
libsfml-audio-d.so         libsfml-graphics.so.2.0   libsfml-system.so.2
libsfml-audio-d.so.2       libsfml-network-d.so      libsfml-system.so.2.0
libsfml-audio-d.so.2.0     libsfml-network-d.so.2    libsfml-window-d.so
libsfml-audio-s.a          libsfml-network-d.so.2.0  libsfml-window-d.so.2
libsfml-audio-s-d.a        libsfml-network-s.a       libsfml-window-d.so.2.0
libsfml-audio.so           libsfml-network-s-d.a     libsfml-window-s.a
libsfml-audio.so.2         libsfml-network.so        libsfml-window-s-d.a
libsfml-audio.so.2.0       libsfml-network.so.2      libsfml-window.so
libsfml-graphics-d.so      libsfml-network.so.2.0    libsfml-window.so.2
libsfml-graphics-d.so.2    libsfml-system-d.so       libsfml-window.so.2.0
libsfml-graphics-d.so.2.0  libsfml-system-d.so.2     pkgconfig
libsfml-graphics-s.a       libsfml-system-d.so.2.0   python2.7
libsfml-graphics-s-d.a     libsfml-system-s.a        python3.3
libsfml-graphics.so        libsfml-system-s-d.a
libsfml-graphics.so.2      libsfml-system.so

And their is no libary called "-lsfml-graphics" .   When i use this command, wich libary is in use? the libsfml-graphics-d.so or the libsfml-graphics.so ?   Or is this depends by commands i give the compiler . For example:

-lsfml-graphics -lsfml-window -lsfml-system   ->   compiling the release binarys
-g -lsfml-graphics -lsfml-window -lsfml-system -> compiling the debug binarys

? Or did i missunderstand here something totally?

best regards :) !

Anonymouseable

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Linux , how to link static?
« Reply #12 on: July 15, 2013, 11:42:35 pm »
-lsfml-graphics will make ld search the library path (usually /usr/local/lib and /usr/lib and /lib among others) for libsfml-graphics.so (which should be a link to libsfml-graphics.so.2 which in turn should be a link to libsfml-graphics.so.2.0). To use the debug version you'd use -lsfml-graphics-d - so you do have to specify. This is not necessary when using a build system like cmake which will select the libraries necessary depending on the kind of build you've asked it to produce (if you write the CMakeLists.txt correctly.)

Chi

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: Linux , how to link static?
« Reply #13 on: July 16, 2013, 09:03:03 am »
Ah okey :) Thank you !

 

anything