wiki

Help! I'm trapped in a wiki!

Site Tools


lang:dynamic_libraries

Dynamic libraries

Dynamic libraries are like static libraries, with the exception that they're not bundled them along with our program and only load them when needed.

As a starter, you can create dynamic libraries by passing some options to a compiler like gcc:

  1. Compile library functions with the -fPIC options
  2. Create the dynamic library with -shared -o libcool.so.1 func1.o func2.o
  3. Link everything with -L. -l:libcool.so.1

>Here, the -L. tells gcc to use the current dir too when searching for libraries (add to the library search path)

Then you can run it with LDD_LIBRARY_PATH=. ./coolprogram

One thing to note is that glibc usually gets implicitly dynamically linked on every build you do, even if you don't use any STL function. Too bad.

@research: how to run normally without specifying library path

lang/dynamic_libraries.txt · Last modified: by 127.0.0.1