Compile multiple C/CPP files under the command line

Source: Internet
Author: User

Last time I talked about the nmake command of ms to compile multiple cpp files. This time, I want to step by step without the help of makefile.

Pay attention to the following points:

1. # The mechanism of the include command is to copy the content in the. h file to the. cpp file, so you only need to compile the cpp file. The H file is just a foil. Note that the declaration statement in. h must be filled with a semicolon to end the process. Otherwise, an error will be reported in the Compilation Program. You can save the H file and directly add it to the cpp file. However, in each subsequent file, you need to rewrite the declaration of this class or function. This is also the reason for the existence of the H file.

2. You can use the cl-c command to compile a class file. After compiling it into an obj file, you can use the lib command to compile it into a lib file. Then use the link command to connect multiple obj files. The default executable file name is the name of the first obj file in the command.

View my example

++ ++

# Include <iostream>
Class {
Public:
Int;
Int B;
Void say ();

};

++ ++

/**
Class {
Public:
Int;
Int B;
Void say ();

};
*/
# Include "A. h"

Void A: say (){
A = B;

}

++ ++

// # Include <iostream>
# Include "A. h"
Using namespace std;

Int main (){
A;
A. a = 0;
A. B = 9;
A. say ();
Cout <a. a <"" <a. B <endl;
}

Here is a question that I want to emphasize. Many students may not care about the multi-inclusion of # include. In fact, # include is only a replication mechanism. You can directly include the iostream in the H file of A, so you do not need to include it again in main. Maybe many of you don't care about it.

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.