Newbie question about compilation
Fri Sep 12 21:50:00 GMT 2003

If you want to compile each of the files into object files before linking them all together, then you need to add "-c" to the command line.  This tells GCC to stop after the .o file is created.  Then, you can run GCC with all the object files and create your program:

gcc -o prog_name main.o dutils.o

This will link to object files together into the main program named "prog_name".  You can, of course, change the output name to something else more appropriate.  Otherwise, you can compile and link all your source files at once like this:

gcc -o prog_name main.c dutils.c

This will compile both source files and write your program out to "prog_name".  

Lyle Taylor
IS Applications

-----Original Message-----
From: Andre Kirchner []
Sent: Friday, September 12, 2003 3:45 PM
Subject: Newbie question about compilation


how can I compile a program that is divided in many .h
and .c files?
I have done this program divided in these files


# include <stdio.h>
int makeDir();


# include "dutils.h"

int makeDir()
        printf( "worked\n" );
        return( 1 );


# include "dutils.h"

int main()
        return( 0 );

But when I try to compile it I got this error message

[andre@Deutschland asp2]$ gcc ./main.c -o ./main.out
/tmp/ccIA1jr7.o(.text+0x11): In function `main':
: undefined reference to `makeDir'
collect2: ld returned 1 exit status



Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

More information about the Gcc-help mailing list