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

Author Topic: Dynamic linkage curiosity (linux)  (Read 1207 times)

0 Members and 1 Guest are viewing this topic.

TheOm3ga

  • Newbie
  • *
  • Posts: 15
    • View Profile
Dynamic linkage curiosity (linux)
« 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

OniLinkPlus

  • Hero Member
  • *****
  • Posts: 500
    • View Profile
Dynamic linkage curiosity (linux)
« Reply #1 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).
I use the latest build of SFML2

TheOm3ga

  • Newbie
  • *
  • Posts: 15
    • View Profile
Dynamic linkage curiosity (linux)
« Reply #2 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.