SFML community forums

Help => General => Topic started by: TheOm3ga on September 21, 2011, 11:32:31 pm

Title: Dynamic linkage curiosity (linux)
Post by: TheOm3ga on September 21, 2011, 11:32:31 pm
Hi there.

I was wondering, why isn't it necessary to link all the dependencies when I compile a game using SFML? For example, I'm now dealing with a game about audio, so I use -lsfml-graphics and -lsfml-audio. However, if I inspect the compiled program:

Code: [Select]
ldd ./programa
linux-vdso.so.1 =>  (0x00007fff2ee8e000)
libsfml-audio.so.1.6 => /usr/lib/libsfml-audio.so.1.6 (0x00007f8244546000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f8244240000)
libm.so.6 => /lib/libm.so.6 (0x00007f8243fbc000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f8243da6000)
libc.so.6 => /lib/libc.so.6 (0x00007f8243a23000)
libsfml-system.so.1.6 => /usr/lib/libsfml-system.so.1.6 (0x00007f8243819000)
libsndfile.so.1 => /usr/lib/libsndfile.so.1 (0x00007f82435b4000)
libopenal.so.1 => /usr/lib/libopenal.so.1 (0x00007f824335c000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8244789000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00007f824313e000)
libFLAC.so.8 => /usr/lib/libFLAC.so.8 (0x00007f8242ef4000)
libvorbisenc.so.2 => /usr/lib/libvorbisenc.so.2 (0x00007f8242a25000)
libvorbis.so.0 => /usr/lib/libvorbis.so.0 (0x00007f82427f8000)
libogg.so.0 => /usr/lib/libogg.so.0 (0x00007f82425f1000)
librt.so.1 => /lib/librt.so.1 (0x00007f82423e9000)
libdl.so.2 => /lib/libdl.so.2 (0x00007f82421e4000)


There are many other libraries, specially libopenal, that get "automatically linked". How do you do it? It's interesting.

I've used OpenAl in other projects, and in all of them I had to either manually link using -lopenal, or use something like the output of pkg-config --libs
Title: Dynamic linkage curiosity (linux)
Post by: OniLinkPlus on September 22, 2011, 01:25:41 am
ldd inspects not just the program you're looking at, but also all of its dependencies (I think, don't take this as fact).
Title: Dynamic linkage curiosity (linux)
Post by: TheOm3ga on September 22, 2011, 01:55:32 am
Never mind, I've made a quick test to see for myself and solved my doubts. I didn't know that, if you create a library and link its dependences when creating the .so file, then you don't need to link them later when you use the library. Quite curious.