The development and management of Linux/C + + programs (makefile)

Source: Internet
Author: User

First, Introduction

Since we were just beginning to write a simple C + + "hello,world! "To compile it, run the results-this part of the work of the IDE (integrated development environment) has helped us, including syntax error checking, compiling, debugging, and executing the binaries. Most of the time we only focus on the program code itself, how to effectively manage C + + source code under Linux, including compiling, linking, debugging, make tools can help us to do this part of the work.

Second, from "Hello,world" talk about

  1. Execute a single source file

A well-written C or C + + code source program needs to compile, link, and so on to generate executable binaries.

For example: Source file: HELLO_WORLD.C's source code is:

      

[1] Step one: Compile build target file hello_world.o (gcc-c hello_world.c)

[2] Step two: Link (there is only one hello_world.o) generate executable Hello_world (gcc-o hello_world hello_world.o)

2. Compiling multiple source files

For example: source files: hello_world.c say_ok.c and MAIN.C source program code are:

You need to generate an executable file for the project containing this three source program file main

[1] Generate target object file (OBJ):

[2] The link is delivered as an executable file, main:

Iii. managing multiple source program Files

Usually we do not have a single source file program (Main.c/main.cpp) when writing a project, in general there will be multiple source files (. c/.cpp) and header files that need to be managed. As described earlier if there are three source files hello_world.c, say_ok.c, main1.c, every time when we modify the source code, we have to rerun all the compilation commands, imagine if the file more than three, but there are many times ... This will undoubtedly be a disaster for programmers. Therefore, we must seek an effective source code management method-make mechanism can help us solve this problem.

1. Make

The make command is one of the most frequent commands used by system administrators and programmers. Administrators use it to compile and install many open-source tools through the command line, which programmers use to manage their large, complex project compilation problems.

2. makefile File Writing format

Target: Raw materials

<Tab> processing methods

3. Makefile Instances

4. Make common options

[1]-b option: The Make command does not compile files that have not changed since the last compilation, but if you want to overwrite the default behavior of made, you can use the-B option

[2]-g option: Debug option for GDB debugging

[3]clean: Clears all current object files and executes files.

The development and management of Linux/C + + programs (makefile)

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.