Nested invocation examples of shared libraries in Linux

Source: Internet
Author: User

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:

    1. -I followed by the path of the header file,-I. Indicates the search header file under the current directory
    2. -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.
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.