Simple shared library

  • Is the STD library a shared library or what is it? out of curiosity.
  • Are there any books detailing the overall development of static libraries?
  • Is there a tutorial?

ps (I use netbeans, eclipse, anjuta) and the tutorials are not useful as I try to understand what is really happening.

+3
source share
2 answers

On my platform (Ubuntu Maverick) this is:

g++ test.cpp
ldd a.out

linux-vdso.so.1 =>  (0x00007fffee1ff000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f18755fd000)
libm.so.6 => /lib/libm.so.6 (0x00007f187537a000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00007f1875163000)
libc.so.6 => /lib/libc.so.6 (0x00007f1874de0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f1875920000)

Pay attention to libstdc ++. so.6 above.

With cmake, creating a shared library is very simple.

1. Install cmake 2.6 or later.

2. Create a test.cpp file with the code for your library.

3. Create the CMakeLists.txt file:

cmake_minimum_required(VERSION 2.6)
project(TEST)
add_library(test SHARED test.cpp)

4. cmake, make :

cmake -G "Unix Makefiles"

5. make .

CMake Eclipse CDT,

cmake -G "Eclipse CDT4 - Unix Makefiles"

.

+7

1.) STD ?

. . , , . ? - , , / , , .


, (/) , . , , () . - , , . , , . ...


, ... ar randlib. :.

g++ -c foo1.C -o foo1.o
g++ -c foo2.C -o foo2.o
ar -rv libfoo.a foo1.o foo2.o
ranlib libfoo.a

:

g++ testfoo.C -o testfoo -L. -lfoo

, , -lbar1 -lbar2 (g++ testfoo.C)! , / . BAD!

foo1.o foo2.o ar, .


...

, fedora core 3, Linux. , fooLibrary.c, :

g++ -shared -Wl,-soname,libfooLibrary.so.1 -o libfooLibrary.so.1.0 -fPIC fooLibrary.c -ldl

LD_PRELOAD, script :

export LD_PRELOAD=libfooLibrary.so ; export LD_LIBRARY_PATH=. ; ./myTestProgram

( , , LD_PRELOAD , g++, ls, cd .., .)

(FYI: strace ... ldd nm.)

, , dlopen() dlsym() - ...

, LD_LIBRARY_PATH ...

( , , malloc(), , - dlopen()/dlsym() malloc(). , malloc() , malloc(). Fun times ...)


PS : gcc/g++. ...

http://gcc.gnu.org/onlinedocs/gcc-4.5.1/gcc/index.html#toc_Invoking-GCC

+2

Source: https://habr.com/ru/post/1771554/


All Articles