Build Failures. "(.text+0x0): multiple definition of `[Just about every thing in the codes]'

I have a fairly simple program for an Arduino Nano, and I am using VS code with PlatformIO.

The first time I built it there was no problem, I made changes to main() and now on building i get output like this.

Building in release mode
Linking .pio/build/nanoatmega328/firmware.elf
.pio/build/nanoatmega328/src/main.cpp.o (symbol from plugin): In function `ts_1_end_us':
(.text+0x0): multiple definition of `ts_1_end_us'
.pio/build/nanoatmega328/src/Ver1_main.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/nanoatmega328/src/main.cpp.o (symbol from plugin): In function `ts_1_end_us':
(.text+0x0): multiple definition of `speed_1_measured'
.pio/build/nanoatmega328/src/Ver1_main.cpp.o (symbol from plugin):(.text+0x0): first defined here
.pio/build/nanoatmega328/src/main.cpp.o (symbol from plugin): In function `ts_1_end_us':
(.text+0x0): multiple definition of `curtain_1_measured'
.pio/build/nanoatmega328/src/Ver1_main.cpp.o (symbol from plugin):(.text+0x0): 
....... Multiple lines like this.
(.text+0x0): multiple definition of `setup'
.pio/build/nanoatmega328/src/Ver1_main.cpp.o (symbol from plugin):(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
*** [.pio/build/nanoatmega328/firmware.elf] Error 1
==================================================================== [FAILED]

I seem to be doing something wrong, but what?

Edit.
I created a new main.cpp and renamed the old main.cpp to Ver1_main.cpp. The build process seems to be using both hence the duplications I guess (and it is only a guess). But how do I stop it using Ver1_main.cpp in the build if that is in fact the issue?

Edit of the edit.
I have sort of solved the issue by abandoning PlatformIO, renanimng the main.cpp file to main.ino and using the Arduino IDE, which just works. Its a shame to have to do this as PlatfomIO in VS code was recomended as the way to go. But “just works” wins out over multiple lines of errors, that I sort of understand but have no idea where to start to fix.

Every .c and .cpp file will be compiled. Remove it from the src folder or renname the file extension to something different than .c or .cpp - like .save

Thanks for that.

I have changed the extension to .txt and that has solved the issue. Wasn’t intuitive, but sort of makes sense.

Next question. How do I mark this as solved?

Edit. Have just noticed the solution button!!!

1 Like