First you will need to have a compiler on your machine. In Ubuntu/Linux land
the compiler is called g++. The normal C compiler is called gcc.
Notice the similarity in names. In fact you can think of C++ as an extension of the
classic C language. In Unbuntu type the following at a terminal prompt:
sudo aptitude install build-essential
and you will automatically get the g++ compiler installed.
To be sure everything works, do your first program by typing this in your editor
and calling it
hello.cpp
You then compile it with:
g++ hello.cpp -o test
You type:
./test
to run it and you should see Hello world!
There are numerous good C++ tutorials on the web, please look at
this one for starters:
C++ Tutorial
We can use the same cgi-bin directory we referenced earlier in the
Perl
scripting section. On Ubuntu with Apache2 this defaults to:
/usr/lib/cgi-bin
Here to make things simple we will show how to run a very simple script using plain old
C to multiply two numbers in a form. The C program
mult.c
To compile type:
gcc mult.c -o /usr/lib/cgi-bin/mult.cgi
Now you can simply squeeze the
form in your main "index.html" page.
If it was a C++ program you would type:
g++ mult.cpp -o /usr/lib/cgi-bin/mult.cgi
This should be enough to get you started! I will add more programs in C++ for you later.