Moep Meep Moep Meep - 2 months ago 13
Linux Question

How to choose between shared and static library?

I'm trying to run the standard example from the SFML Library in Linux. I have download the Rep. from Github, build and install it with CMake. I have build 2 Libraries for static/shared debug, and 2 Libraries for static/shared Release.

The problem now, I don't know much about compiling in the Terminal. I use the commands I found on the SFML Website:


g++ -c test.cpp

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


that works. I can run my SFML Application by ./sfml-app and double-click. But other people who (who have not installed SFML) using Linux cant. And I think it's because the compiler does not use the static libraries. Of course - how he could? It's not written in the command. But I also don't know how to write it.

The name of the static-release libraries is for example


libsfml-graphics-s.a

libsfml-window-s.a

libsfml-system-s.a


what must I write in g++, that he is using this libs when he link the stuff?

Answer

To link your program against the static versions of the libraries, you would do the following:

g++ test.o -o sfml-app libsfml-graphics-s.a libsfml-window-s.a libsfml-system-s.a

(Assuming, of course, that these files are in your local directory.)