Simple description of compiler instructions for g++ compiler in algorithm contest

Source: Internet
Author: User

The online problem-solving platform used in the algorithm contest will give you the instructions for compiling the code to be compiled by the FAQ. For example, the C + + compiler directive given by Hustoj is usually:

C++: g++ Main.cc-o main-fno-asm-o2-wall-lm--static-donline_judge

These seemingly useless instructions actually do indeed work. So what do these instructions mean?

    • -O Main: This is the parameter that indicates the output file name, where the file name is Main. For algorithmic contests this doesn't seem necessary to know.
    • -fno-asm: This meaning and literal (do not let the assembly) Chabudu, that is, the function is not to put asm,inline,typeof as a keyword. Then, cannot use the assembly, cannot use the inline, cannot use the TypeOf. Here are some restrictions, not a good thing ...
    • -o2: Optimization directives. You can indicate the optimization level with numbers later. -o0 is not optimized, and the-O1,-O2,-O3 optimization is increased successively. Oi Competition is not open optimized, ACM is O2. Examples of optimizations, such as compiler-open optimizations, int type *2/2, are optimized to >>/<< (bitwise operations). It is said that optimization can sometimes reveal the omissions in the code (especially-o3). So it might help to find the wrong thing in the competition. But the optimization level is too high for debugging. Because in order to optimize, the compiler may disrupt the order of parts of the code, causing us to step into the debugging time will find in the C source code in the random jump.
    • -wall: This doesn't mean the wall xd. W is a warning and all is a display of most warnings. All means all but the actual is mostly, this is because some warnings need to be opened manually. Like what.. -wfloat-equal This command gives a warning when the floating-point number uses = = To determine equality, and so on.
    • -lm:link Math. Use the Math library. This is nothing to say ...
    • --static: statically linked compilation directives. This allows the program to no longer rely on external function libraries to run. (So I used the QT compiler program is not dependent on various Qtxxxx.dll =). This is a game for algorithms that seems to be ignored.
    • -donline_judge:define Online_judge. In other words, you can write code that is easy to debug, and then let it be executed after the commit. The more common usages are in "#ifndef Online_judge" and "#endif" Middle plug "freopen (" Output.txt "," w ", stdout);" redirect the output stream. Wait a minute.
    • -G: Debug directives. Plug in the debugging information into the program. This is not in the above parameters (nonsense ...). ), the reason mentioned here is that when using Code::block, if debugging is not available, you need to add this parameter.

The reason for this is that most of the previous compilation instructions were not very clear, so I wrote a summary of the nature of the list according to the document and the actual application. Well, it should be used in the future. For example, open O3 to see if you can figure out what's wrong with the code (not yet) and use Online_judge (which has been used before).

This content, should be in the compilation principle in the future to learn it.

Simple description of compiler instructions for g++ compiler in algorithm contest

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.