Pro-Test Success!
Reference URL:
Nested routines: https://my.oschina.net/moooofly/blog/506466.html
Linux cannot find a dynamic link library. So file resolution Https://www.cnblogs.com/xudong-bupt/p/3698294.html
Linux shared library, static library, dynamic library detailed:
Https://www.cnblogs.com/sunsky303/p/7731911.html
Create a new test folder and create a new file within this folder:
Vim Hello.cpp
Vim Hello.h
Vim Usehello.cpp
Vim Usehello.h
1. Compiling the dynamic link library
gcc -o hello.so -fpic -shared -I. hello.cpplsldd hello.so
gcc -o usehello.so -fpic -shared -I. -Wl,-rpath=/home/yzw/test usehello.cpp hello.so lsldd usehello.so
Remember that the shared library is written after the. cpp file, otherwise it will not load the dynamic-link library
gcc -o main -I. -Wl,-rpath=/home/yzw/test main.cpp usehello.solsldd main
./main '
Note:
- -I followed by the path of the header file,-I. Indicates the search header file under the current directory
- -wl,-rpath=/home/yzw/test represents a shared library address that specifies a priority search, first your address must be in the/etc/ld.so.conf file, or in the/etc/ld.so.conf.ld directory.
- Additional Notes from link one:
Ldconfig naming is associated with running a program city, and there is no relationship at compile time, so you still need to add precedence to the specified library path at compile time, such as:-wl,-rpath=/home/yzw/test
Nested invocation examples of shared libraries in Linux