20080429
20080420
gcc如何编译出动态链接的可执行程序
Re: gcc如何编译出动态链接的可执行程序?
发信站: 水木社区 (Sun Apr 20 15:59:25 2008), 站内
发信站: 水木社区 (Sun Apr 20 15:59:25 2008), 站内
----
creating a shared library
----
gcc -c -fPIC test1.c
gcc -shared -fPIC -o libtest1.so test1.o
----
link a shared lib is just like linking with a static archive
----
gcc -o app app.c -L. -ltest1
----
When link a program withe a shared library, the linker (usually) does not
put the full path to the shared library.
When the program is actually run, the system searches for shared library
and load it. If it does not find, system will refuse to run the program.
* one solution: use the -Wl,-rpath,/usr/local/mylib
to program your lib path in executable file.
* another: use $LD_LIBRARY_PATH
--
重剑无锋,大巧不工。
Subscribe to:
Posts (Atom)