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