1.2. Building a Simple “Hello, World” Application from the Command Line
Problem
You want to build a simple “Hello, World” program, such as that in Example 1-4.
Example 1-4. A simple “Hello, World” program
hello.cpp
#include <iostream>
int main()
{
std::cout << "Hello, World!\n";
}Solution
Follow these steps:
Set any environment variables required by your toolset.
Enter a command telling your compiler to compile and link your program.
Scripts for setting environment variables are listed in Table 1-5; these scripts are located in the same directory as your command-line tools (Table 1-3). If your toolset does not appear in Table 1-5, you can skip the first step. Otherwise, run the appropriate script from the command line, if you are using Windows, or source the script, if you are using Unix.
Table 1-5. Scripts for setting environment variables required by your command-line tools
|
Toolset |
Script |
|---|---|
|
Visual C++ |
vcvars32.bat |
|
Intel (Windows) |
iclvars.bat [2] |
|
Intel (Linux) |
iccvars.sh or iccvars.csh |
|
Metrowerks (Mac OS X) |
mwvars.sh or mwvars.csh[3] |
|
Metrowerks (Windows) |
cwenv.bat |
|
Comeau |
Same as the backend toolset |
[2] With earlier version of the Intel compiler, this script was named iccvars.bat. [3] In versions of CodeWarrior prior to 10.0, there was a single csh script named mwvars. | |
Commands for compiling and linking hello.cpp are given in Table 1-6. To work properly, these commands require that your current directory is the directory containing hello.cpp and that the directory containing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access