During linux compilation, multiple source files generate one target file.

Source: Internet
Author: User

During linux compilation, multiple source files generate one target file.

Obj-m: = target. o

Target-objs: = src1.o src2.o src3.o


How to compile a source file and a header file simultaneously in linux shell to generate an executable file

Compile the. c file directly with gcc, And the # include "header file" in the. c file.
Gcc test. c-o output-Wall
Among them, output is the output executable file, and the-Wall switch is used to display all warning information.

Multi-file compilation in C language in linux

If there are multiple source files, there are basically two compilation methods:
[Assume there are two source files: test. c and testfun. c]

1. Compile multiple files together
Usage: # gcc testfun. c test. c-o test
Purpose: Compile testfun. c and test. c respectively and link them to the test executable file.

2. compile each source file separately, and then link to the target file output after compilation.
Usage:
# Gcc-c testfun. c // compile testfun. c into testfun. o
# Gcc-c test. c // compile test. c into test. o
# Gcc-o testfun. o test. o-o test // link testfun. o and test. OTO test

Compared with the above two methods, the first method requires all files to be re-compiled during compilation, while the second method can only re-compile the modified files, and the unmodified files do not need to be re-compiled.

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.