Compiling C + + files in Linux environment _ static function

Source: Internet
Author: User

Recently, you need to upload your code to GitHub, which allows the code to be compiled and run on Ubuntu. I learned a little bit about how to compile C + + files in the Ubuntu environment. A single source file generates an executable program

Casually write a simple program:
    /*test.cpp*/
#include <iostream>
int main (int argc,char *argv[])
{
    std:: cout << "Hello, World" << Std::endl;
    return (0);
}

Can be directly g++ test.cpp compile, * compiler default action: * Compile source code file to generate object file, link object file and function in LIBSTD C + + library to get executable program. The object file is then deleted. The compiler takes the default a.out because the file name of an executable program is not specified on the command line. Programs can run like this:./a.out

However, the general practice specifies the output name, as follows:
g++ test.cpp-o test multiple source files to generate an executable file:

In fact, the compiler is now very smart, you only need to put all the engineering use of the. cpp and. h files under the same file directory, and then g++ *.cpp-o test can be compiled into an executable file.

Note: It should be noted that if the method used in the project is not in the standard library, then you need to rewrite this method. For example, I use vs 2012 to build the project inside the STRLWR method is not in the standard library, then the use of Linux compilation will be reported without the definition of errors.

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.