Hi,
I have written many projects using Atmel Studio 4 and 6.2. My practice is to use a well structured modular approach, with modules comprising .c and .h files. Public variables and functions are defined in the .c file and are declared as extern in the .h file. To avoid multiple declarations, I always enclose all .h declarations in [#ifndef _MODULE_H, define _MODULE_H, {declarations}, #endif] structures.
I'm using Atmel Studio 6.2 because I'm in the process of getting the project ready to transfer to the client, and want to remain on the IDE version that's been successful during development up to now, if possible. So I haven't upgraded to AS7 yet. I'm using the native GNU toolset.
Adding a couple more modules, I've just begun the get Multiple Definitions errors which make no sense to me. An example of the relevant output is given below:
Building target: Proj.elf Invoking: AVR/GNU Linker : 4.8.1 "C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\Native\3.4.1061\avr8-gnu-toolchain\bin\avr-gcc.exe" -o Proj.elf accel.o eeprom.o flash.o function.o gnss.o gsm.o inputs.o panel.o tcp.o power.o rtc.o serial_gsm.o spi.o time.o uid.o adc.o commands.o console.o i2c.o status.o main.o timebase.o atomic.o -Wl,-Map="Proj.map" -Wl,-u,vfprintf -Wl,--start-group -Wl,-lprintf_flt -Wl,-lm -Wl,--end-group -Wl,--gc-sections -Wl,--defsym=__stack=0x2FFF -mmcu=atxmega64a3u tcp.o: In function `tcp_init': C:\Path\Working\default/.././tcp.c(79,1): error: multiple definition of `tcp_init' panel.o:C:\Path\Working\default/.././tcp.c:79: first defined here tcp.o: In function `tcp_connect': C:\Path\Working\default/.././tcp.c(94,1): error: multiple definition of `tcp_connect' panel.o:C:\Path\Working\default/.././tcp.c:94: first defined here tcp.o: In function `tcp_init': C:\Path\Working\default/.././tcp.c(79,1): error: multiple definition of `tcp_connected' panel.o:C:\Path\Working\default/.././tcp.c:79: first defined here tcp.o: In function `tcp_disconnect': C:\Path\Working\default/.././tcp.c(217,1): error: multiple definition of `tcp_disconnect' panel.o:C:\Path\Working\default/.././tcp.c:217: first defined here tcp.o: In function `tcp_send': C:\Path\Working\default/.././tcp.c(239,1): error: multiple definition of `tcp_send' panel.o:C:\Path\Working\default/.././tcp.c:239: first defined here collect2.exe(0,0): error: ld returned 1 exit status make: *** [Proj.elf] Error 1 The command exited with code 2. Done executing task "RunCompilerTask" -- FAILED. Done building target "CoreBuild" in project "Proj.cproj" -- FAILED. Done building project "Proj.cproj" -- FAILED. Build FAILED. ========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
If I comment out the #include "tcp.h" from one module, the errors disappear, but then I can't access tcp functions from that module. The errors make no sense to me, there are no duplicate definitions, and the tcp.h file only includes extern declarations, not definitions. Futhermore, the first error, shows correctly that the function `tcp_init' is defined in line 79, but it is not defined elsewhere. And the third error, complaining that the variable `tcp_connected' is defined on the same line 79 is patently false. That variable is defined on line 44 and is declared as extern in tcp.h.
I have searched the web and this forum for similar issues, and the most similar post recommends a tutorial at https://www.avrfreaks.net/forum/tut-modularizing-c-code-managing-large-projects?name=PNphpBB2&file=viewtopic&t=48535, which I've read and which already describes the standard structure I use.
Has anyone encountered similar issues with large multi-module projects like this? Is there a limit on the number of modules that can be linked? Is there an issue with the scope of #define _MODULE_H definitions, which may cause my multiple declaration protection to fail? Anyone got any other thoughts on why this is occurring and what I can try to solve it?
For confidentiality reasons, I can't publish or share the code, but I may be able to post redacted extracts if that will help.
Many thanks in advance to anyone taking the trouble to read or respond to this. It's most frustrating!