Sunday, April 17, 2005

How to create a console application

Here's an example. The following is a code sample for a simple C program. Cut and paste it into a file named hello.c to try it out.

#include

int main(int argc, char **argv)
{
printf ("Hello\n");
return (0);
}

If you want to create a console mode executable hello.exe from a c file called hello.c, try the following:
gcc -c hello.c

This compiles hello.c into an object file, hello.o
gcc -o hello hello.o

This creates an executable hello.exe from hello.o. Alternatively, you can compile and link in one step using:
gcc -o hello hello.c

The following is a code sample for a simple C++ program. Cut and paste it into a file named hello.cpp to try it out.

#include
int main(int argc, char **argv)
{
cout << "Hello" << endl;
return (0);
}

For the C++ program, use the following to compile and link:

g++ -c hello.cpp
g++ -o hello hello.o

No comments: