The establishment of C language Dynamic link library

Source: Internet
Author: User

Below we create a dynamic link library.

Recalling the previous article about the establishment of a static link library, we put these files into a new directory:

Makefile Tiaoshen.c mmc.h xu.c

You can also create your own new documents, which are not mentioned here.

Makefile file, change to

All

GCC Tiaoshen.c-o tiaoshen.o-c-fpic

Gcc-o libtiaoshen.so tiaoshen.o-shared

-fpic is compiled to a location-independent code, which can then be loaded anywhere to execute

-shared means a shared library.

The makefile is then compiled (note the white space in front of the GCC in makefile, which is the TAB key)


Use our Library of links:

You directly include the header file and then use it is not possible, generally you create a. So file is not in the fixed directory it looks for, there are two ways to solve

1, CP Libtiaoshen.so/usr/lib can, this is the system comes with the library function file

2. Use environment variables export ld_library_path= $LD _library_path: (Follow the path of your dynamic library)

Then compile:

GCC xu.c-o shen-ltiaoshen-l.

Then you can run it!


The establishment of C language Dynamic link library

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.