Generate a dynamic link library using automake

Source: Internet
Author: User
Tags automake

Recently, I changed a project to be implemented using C ++. Previously, the project was compiled using automake. The previous time I learned how to use automake for compilation, I thought it was okay, however, many problems are found in practice, especially when using the Linked Library. After learning about it, I will record the usage method and review it later. I hope that you can find a reference for a friend who has encountered a problem.

1. Use automake to generate a dynamic link library

Suppose we have a project named "test". There are two sub-directories named "fun" and "src" under "test". (The file name is not very standard. I hope you will forgive me) and "fun" is available under the "fun" directory. CPP and fun. h two source files. Now I want to compile these two source files to generate a dynamic link library libfun. so, the main. CPP file, Main. the CPP file will call libfun. so dynamic library.

The automake compilation process is as follows:

  • Create a new file makefile. AM in the fun directory. The file content is:


Automake_options is the automake option. Automake is mainly used to help GNU software developers maintain the software. Therefore, when executing automake, it will check whether there are files in the standard GNU software in the directory, for example, files such as 'News', 'author', and 'changelog. When it is set to foreign, automake will use the standard of general software to check. If this sentence is not added, run touch news readme authorschangelog to generate 'News', 'author ',
Use automake to generate dynamic link libraries for files such as 'changelog.

Lib_libraries indicates that the dynamic link library will be generated. The equal sign is followed by the name of the dynamic link library. Note that the extension name is. La.

The third line describes the files required to generate a dynamic link library.

  • Create the makefile. Am file in the src directory with the following content:

In this example, "des" indicates the directories of other header files to be included in the final program. If there are multiple directories, separate them with spaces.

Bin_programs indicates the name of the final executable program.

Resources indicates the source files used to generate executable programs.

The fourth line indicates the path of the dynamic link library used (note that ldadd is used later)

  • Run autoscan in the project root directory test, change Configure. Scan to configure. In, and modify Configure. In as follows:

Ac_init is needed. The name, version number, and contact information of the final release program must be filled in brackets.

Add an ac_init_automake line;

Add a line of ac_prog_libtool (indicating that dynamic library is used)

Run the aclocal, libtoolize-F-C, Autoconf, and autoheader commands.

Create the makefile. Am file with the following content:

The first line is still the Specification Description. If this line of automake does not exist, it will require readme news and other files. In this case, you need to use the touch news readme authors changlog command to generate the required files.

The second line shows the path of the makefile of the project. However, you 'd better put Fun in front of SRC. Otherwise, you need to run make in the fun directory before running it in the root directory. Otherwise, an error will be reported and the dynamic library cannot be found. The reason should be that the running order is in the subdirs order ..

Run the automake-a command to generate the makefile. In file under all three files.

Run the./configure -- prefix = · PWD · command to generate the MAKEFILE file.

Run make and make install (the first time you run make, it seems that you need to run make under the fun directory, and then run make under the root directory)

At this time, the corresponding dynamic link library and executable program are generated under the fun and SRC directories.

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.