RE: Newbie question about compilation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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".  

Thanks,
Lyle Taylor
IS Applications

-----Original Message-----
From: Andre Kirchner [mailto:sieg1974@xxxxxxxxx]
Sent: Friday, September 12, 2003 3:45 PM
To: gcc-help@xxxxxxxxxxx
Subject: Newbie question about compilation

Hi,

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

dutils.h:

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

dutils.c:

# include "dutils.h"

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

main.c:

# include "dutils.h"

int main()
{
        makeDir();
        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

Thanks,

Andre

__________________________________
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software
http://sitebuilder.yahoo.com


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux