C++ compiling in Linux

_very_ briefly
When I started working with c++ in linux, my first question was:
How on earth do I compile this ?
I tried cc, gcc, g++ and many others by just giving sourcefile after command : g++ test.c
But all I got was just errors. And I found that fellow geeks had same problem for starters...

So, no "big" problems, just dunno how to compile it ;)

Here it goes, just follow how it was done...



[henkka@kotkapoika testit]$ ls -l    
total 2
-rwxrw-r--   1 henkka   henkka         61 heinä   4 21:50 compileIt
-rw-rw-r--   1 henkka   henkka         68 heinä   4 21:47 test.c

[henkka@kotkapoika testit]$ more compileIt
g++ -c -O2 -fno-strength-reduce -o $1.o $1.c
g++ -o $1 $1.o

[henkka@kotkapoika testit]$ more test.c 
#include 

void main(void)
{
cout << "Hello World! \n";
}

[henkka@kotkapoika testit]$ ./compileIt test
[henkka@kotkapoika testit]$ ls -l
total 10
-rwxrw-r--   1 henkka   henkka         61 heinä   4 21:50 compileIt
-rwxrwxr-x   1 henkka   henkka       6083 heinä   4 21:51 test
-rw-rw-r--   1 henkka   henkka         68 heinä   4 21:47 test.c
-rw-rw-r--   1 henkka   henkka       1192 heinä   4 21:51 test.o

[henkka@kotkapoika testit]$ 

[henkka@kotkapoika testit]$ ./test
Hello World! 
[henkka@kotkapoika testit]$ 


So. First step is to create "compileIt" batch-file which contains two lines:

g++ -c -O2 -fno-strength-reduce -o $1.o $1.c
g++ -o $1 $1.o

Then we need to enable "eXecute"-bit:

chmod u+x compileIt

Then we create the source-file, here it was test.c with lines

#include 

void main(void)
{
cout << "Hello World! \n";
}

Then we just compile it:

./compileIt test

Notice that we just pass filename before the dot, not after ! (So "test" is actually "test.c"...)
After that we should have actual "test" - executable, and we can run that...

And here is more compicated example of "compileIt"-batchfile:

g++ -c -I/usr/lib/glib/include -O2 -fno-strength-reduce -o $1.o $1.c
g++ -L/usr/X11R6/lib  -o $1 $1.o  -lX11

So there was couple of include & library directories in it also.


Ok, i think that was about it. Thanks to Timo Lukkarinen I was able to wrote this page.

Henry Palonen, 1999