* RE: Newbie question about compilation
@ 2003-09-12 21:50 lrtaylor
0 siblings, 0 replies; 2+ messages in thread
From: lrtaylor @ 2003-09-12 21:50 UTC (permalink / raw)
To: sieg1974, gcc-help
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@yahoo.com]
Sent: Friday, September 12, 2003 3:45 PM
To: gcc-help@gcc.gnu.org
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Newbie question about compilation
@ 2003-09-12 21:45 Andre Kirchner
0 siblings, 0 replies; 2+ messages in thread
From: Andre Kirchner @ 2003-09-12 21:45 UTC (permalink / raw)
To: gcc-help
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2003-09-12 21:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-12 21:50 Newbie question about compilation lrtaylor
-- strict thread matches above, loose matches on Subject: below --
2003-09-12 21:45 Andre Kirchner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).