Thread: [Dev-C++] Compilation of multiple files
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Jan M. <jan...@vo...> - 2007-07-10 12:07:27
|
Hello, I have problems with compiling using gcc in Dev-C. I am trying to compile two .c and two .h files. In main.h I have preprocesor commands: #ifndef __stdio_h__ #include<stdio.h> #define __stdio_h__ #endif /* and the similarly with standard .h headers. */ #ifndef __bet_list_h__ #include "bet_list.h" #define __bet_list_h__ #endif #ifndef __bet_list_h__ #include "bet_list.h" #define __bet_list_h__ #endif In main.c and bet_list.c I have: #ifndef __main_h__ #include "main.h" #define __main_h__ #endif The output from make is: gcc main.c bet_list.c -o out_exe C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x0):bet_list.c: multiple definition of `bet_no' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x0):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x4):bet_list.c: multiple definition of `max_bet_no' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x4):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x8):bet_list.c: multiple definition of `d_name' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x8):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x10):bet_list.c: multiple definition of `d_description' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x10):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x18):bet_list.c: multiple definition of `d_multiplicator' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x18):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x20):bet_list.c: multiple definition of `d_calculation' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x20):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x28):bet_list.c: multiple definition of `module_name' C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x28):main.c: first defined here C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.text+0xb2):main.c: undefined reference to `print_' collect2: ld returned 1 exit status make: *** [build] Error 1 Anyone knows where is an error. I have tried to do it using just simple #include, without the definition the preprocesor variables but it doesn't work neither. Thank you very much Jan Mura jan...@vo... |
|
From: Per W. <pw...@ia...> - 2007-07-10 14:17:35
|
It seems that you declare variables in main.h and then include the file from two source files. That gets you two sets of variables with the same name. Either modify main.h to contain: extern int my_variable; and in main.c actually instantiate the variables: int my_variable; or modify main.h to contain. #ifdef MAIN_APP #define EXTERN #else #define EXTERN extern #endif EXTERN int my_variable; and in main.c, write: #define MAIN_APP #include "main.h" and in other source files just write: #include "main.h" /pwm On Tue, 10 Jul 2007, Jan Mura wrote: > Hello, > > I have problems with compiling using gcc in Dev-C. > > I am trying to compile > two .c and two .h files. > > In main.h I have preprocesor commands: > > #ifndef __stdio_h__ > #include<stdio.h> > #define __stdio_h__ > #endif > /* and the similarly with standard .h headers. */ > #ifndef __bet_list_h__ > #include "bet_list.h" > #define __bet_list_h__ > #endif > #ifndef __bet_list_h__ > #include "bet_list.h" > #define __bet_list_h__ > #endif > > > In main.c and bet_list.c I have: > > #ifndef __main_h__ > #include "main.h" > #define __main_h__ > #endif > > > The output from make is: > > gcc main.c bet_list.c -o out_exe > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x0):bet_list.c: multiple > definition of `bet_no' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x0):main.c: first defined > here > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x4):bet_list.c: multiple > definition of `max_bet_no' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x4):main.c: first defined > here > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x8):bet_list.c: multiple > definition of `d_name' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x8):main.c: first defined > here > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x10):bet_list.c: multiple > definition of `d_description' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x10):main.c: first > defined here > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x18):bet_list.c: multiple > definition of `d_multiplicator' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x18):main.c: first > defined here > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x20):bet_list.c: multiple > definition of `d_calculation' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x20):main.c: first > defined here > C:\DOCUME~1\tereza\LOCALS~1\Temp/ccqobaaa.o(.data+0x28):bet_list.c: multiple > definition of `module_name' > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.data+0x28):main.c: first > defined here > C:\DOCUME~1\tereza\LOCALS~1\Temp/cc0Yaaaa.o(.text+0xb2):main.c: undefined > reference to `print_' > collect2: ld returned 1 exit status > make: *** [build] Error 1 > > > Anyone knows where is an error. > I have tried to do it > using just simple #include, without the definition > the preprocesor variables but it doesn't work neither. > > Thank you very much > > Jan Mura > jan...@vo... > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |
|
From: Jonathan W. <jon...@gm...> - 2007-07-10 16:44:06
|
Indeed, the preprocessor directives you use aren't well placed: Firstly: You use #ifndef __stdio_h__ #include<stdio.h> #define __stdio_h__ #endif in your files as to not include stdio.h multiple times. however, stdio.h (and any properly built .h file) already deals with this issue (mostly the same way you did): something.h: #ifndef __something_h__ // // body of something.h // #define __something_h__ #endif source and header files using something.h: #include "something.h" Secondly: This mecanism only prevents the multiple inclusion of the .h file on the same compilation run, but every .c file is compiled seperately and then linked together to save effort (imagine recompiling a 300+ file project (or even a 10-file one) just to change one small thing in one file :D ) Jonathan |
|
From: Jan M. <jan...@vo...> - 2007-07-13 12:25:49
|
Thank you very much boys & boys. I am a little bit better C-er again. Jan Mura ----- Original Message ----- From: "Jonathan Winterflood" <jon...@gm...> To: "Per Westermark" <pw...@ia...> Cc: "Jan Mura" <jan...@vo...>; <dev...@li...> Sent: Tuesday, July 10, 2007 6:43 PM Subject: Re: [Dev-C++] Compilation of multiple files > Indeed, the preprocessor directives you use aren't well placed: > > Firstly: > You use > #ifndef __stdio_h__ > #include<stdio.h> > #define __stdio_h__ > #endif > in your files as to not include stdio.h multiple times. > however, stdio.h (and any properly built .h file) already deals with this > issue (mostly the same way you did): > > something.h: > #ifndef __something_h__ > // > // body of something.h > // > #define __something_h__ > #endif > > source and header files using something.h: > #include "something.h" > > Secondly: > This mecanism only prevents the multiple inclusion of the .h > file on the same compilation run, but every .c file is compiled seperately > and then linked together to save effort (imagine recompiling a 300+ file > project (or even a 10-file one) just to change one small thing in one file > :D ) > > Jonathan > > > > __________ Informace od NOD32 2391 (20070711) __________ > > Tato zprava byla proverena antivirovym systemem NOD32. > http://www.nod32.cz > |