[dundee] How to compile
Andrew Clayton
dundee at lists.lug.org.uk
Tue Jun 3 20:35:01 2003
On Tue, 2003-06-03 at 16:51, Keir Lawson wrote:
> how can i change the defualt anjuta compile to output a binary with out
> the .o suffix ?
hmm, it is curious that it would do this.
Certainly with C and gcc you would compile your c program with
gcc prog.c
this would give you an a.out binary
or more usually you would do
gcc -o prog prog.c
which will give you a binary called prog
this .o stuff is for when you have multiple source files that you want
to compile and produce individual object files which can then be linked
with your main program file which contains the 'main' function.
e.g
gcc -c strfuncs.c
gcc -c mathfuncs.c
will produce strfuncs.o and mathfuncs.o
which can then be linked in with your main program
gcc -o prog prog.c strfuncs.o mathfuncs.o
prog.c contains the main function and will also call functions contained
in the two .o files.
OK, heres a VERY basic example.
add.c
int add (int a, int b)
{
int c;
c = a+b;
return c;
}
mul.c
int mul (int d, int e)
{
int f;
f = d * e;
return f;
}
sums.c
#include <stdio.h>
void main ()
{
printf ("addsum = %d, mulsum = %d\n", add (2, 3), mul (5, 8));
}
gcc -c add.c
gcc -c mul.c
gcc -o sums sums.c add.o mul.o
I would have thought that this would be pretty much the same for C++/g++
--
Andrew