Linux Lake 23: Managing C + + projects with Eclipse and GNU Autotools

Source: Internet
Author: User
Tags automake

In all the previous essays in my series, the software was installed and uninstalled using the Linux distribution's own package management tools (such as apt-get, yum, etc.), and never showed you how to use the source code to build the software yourself. But children's shoes, which have long been in the Unix/linux world, know that compiling and installing software from source code is not so difficult, generally three steps:

Configure  Make  Make Install

The ability to manage the source code is so simple, thanks to the Gnu Autotools toolchain. In the above three commands, configure is a script that is powerful and can detect the system environment, such as detecting the build tool version in the system, the standard library version, and other tools that need to be relied upon to generate a makefile, and the subsequent make and make install The software is compiled and installed based on the Makefile that was just generated. It seems simple, but the fact that the Autotools tool chain is very complex and complex is prohibitive to how many times I want to learn these tools. Until I met Eclipse.

First of all, the Gnu autotools, about the use of the tool chain there are a lot of blog posts online, I have a picture here first:

As you can see, the Gnu Autotools contains tools such as AutoScan, Aclocal, Automake, autoconf, Autoheader, and also involves a very old macro language M4. It works like this, first by the AutoScan to scan the source code, generate a Configure.scan file, and then the user to edit the file, generate Configure.in file. The user also writes a file, which is the makefile.am file. The makefile.am and configure.in files are then processed, the makefile.in files are generated, and the autoconf tool processes the configure.in, generating configure scripts, Autohe Automake The Ader tool processes the configure.in file and generates config.h.in files. At this point, the mission of the Autotools tool is completed, and the resulting files can be delivered to the user for use. After the user gets the source bundle, runs the Configure script, which processes the makefile.in file, generates the final Makefile, processes the config.h.in file, and generates the Config.h file. With Makefile, users can compile and install the software using make and do install.

So what do you do with Aclocale orders? This is because the Configure.in file contains a large number of M4 macros that will eventually be expanded into a variety of Shell code to detect the system environment. But the definitions of these macros are often scattered around the system, and the Aclocale command is to collect these macros into a file ACLOCALE.M4.

This toolchain is really too complicated, but I'm glad I have Eclipse. The friends who have read my Java blog know that I am Eclipse powder, and there is not much to say here. Let's see which packages of Eclipse are in Ubuntu's software source, such as:

Command sudo aptitude search eclipse can find out all the software packages that contain the word eclipse, but I want to filter it, not the one that starts with eclipse, including ": I386", because I'm a 64-bit platform, The default package is right for me, so I have the following | grep ' Eclipse ' | Grep-v ': ', finally, add a pipeline that uses the awk command to display only the 2nd column, the name of the package. The results are as shown.

As can be seen from these results, ECLIPSE-CDT is used to write the C/s code of the IDE environment, and there are eclipse-cdt-autotools packages available, it is really in the middle of my wish. But I'm more greedy, I want to install all of these and eclipse-related packages, what to do? There is a way to add it after the above command | Xargs echo sudo aptitude install generates a command to install all of these packages. I redirect the resulting result to a script file, add the Execute permission to the script file, and then run it, such as:

Answer a "Y" and wait patiently for the installation of Eclipse. After the installation is complete, you can start eclipse and choose a C + + project When you create a new project, such as:

Click Next to the following interface:

You can see that there are a number of project types to choose from, and Eclipse can either use its own project file to manage a C + + project or use Makefile to manage the project, and of course we choose to use the Gnu Autotools to manage the project, and choose the simple "Hello World "demonstration project. Click Next, such as:

Enter some information about the project, and then proceed to the next step, such as:

If you click on the "Advanced Settings" button, you can also set the Gnu autotools toolchain in more detail. Such as:

I'm not going to be a fool here, OK? Go back to the dialog box, then click the Finish button, as shown:

Eclipse prompts me to enter a C + + perspective. That is necessary, click the Yes button, the result is as follows:

The left side is the composition of the project file, the right side can see the Makefile of the Target, the top of a row of toolbars, with the hammer is the Build command. Look again:

The button with the arrow is the command to run the program. Running the button with the bug on the left is the debug command. And as you can see, there are fewer files in the project browser on the left before Build, except for the simple CPP file that shows Hello world, only Configure.ac and makefile.am are worth a look. Look at the contents of configure.ac, such as, inside is a few lines of simple M4 macros. Such as:

Build it up, like this:

On the left side of the project view, ACLOCALE.M4, configure scripts, makefile.in and Makefile all have, and the Makefile view on the right can see a full Targets. In the middle, let us see what the legendary M4 macro looks like.

, look at the generated configure script:

More than 4,000 lines, it's horrible. While I'm here Linux Lakes 10:bash the aesthetics and philosophy of the scripting language and everyone has explored Shell scripts, but I never thought I could write more than 4,000 lines of configure files for such a big project. The file is automatically generated.

The same auto-generated file also has Makefile, more than 700 lines, but also enough people to drink a pot, such as:

Select a Makefile target on the right, click the right mouse button and select Build Target from the popup menu to build it accordingly. Isn't it convenient? Such as:

Now, the GUI interface provided by Eclipse is verified with the Gnu Autotools Toolchain as described earlier, does it feel like a sudden understanding?

(Jingshan Ranger in 2015-03-16 published in the blog Park, reproduced please indicate the source. )

Linux Lake 23: Managing C + + projects with Eclipse and GNU Autotools

Related Article

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.