$ Vim Hello. c
# Include <stdio. h>
Int main (void)
{
Printf ("Hello world! /N ");
Return 0;
}
: The wq storage disk is Hello. c.
Enter gcc Hello. c-o hello in the command line (case sensitive)
The following warning may be reported during compilation: no newline at end of file can be supplemented with a new line at the end of the file.
Execution file:./hello
Compile C ++-"Hello world !"
# Include <iostream. h>
Int main ()
{
Cout <"Hello world! /N "<endl;
Return 0;
}
Compilation error: undefined reference to ''cout''
Ah! I don't even know how to connect to cout. Please check out what man says:
Man gcc
Oh, I used to compile the C ++ program with g ++.
G ++ Hello. cpp-o hello
Compilation class
There are three files: Hello. h, Hello. cpp, and MyFirst. cpp. The content is as follows:
File: // Hello. h
# Ifndef HelloH
# Define HelloH
Class Hello
{
Hello ();
Void Display ();
}
File: // Hello. cpp
# Include "Hello. h"
# Include <iostream. h>
Hello: Hello ()
{
}
Hello: Display ()
{
Cout <"Hello world! /N "<endl;
}
File: // MyFirst. cpp
# Include <iostream. h>
# Include "Hello. h"
Int main ()
{
Hello theHello;
TheHello-> Display ();
Return 0;
}
Start Compilation: g ++ MyFirst. cpp-o MyFirst
Ah, an error occurred:
Undefined reference to ''hello: Hello (void )''
Undefined reference to ''hello: Display ()''
Oh, it seems that the connection to Hello. cpp is not allowed. Please change it first.
In MyFirst. cpp: change # include "Hello. h" to # include "Hello. cpp"
After compilation is passed, check the help. If there is a parameter-c, only compilation is not linked.