Please explain .cpp files.
I have been working on a large project without .cpp files because I was fine with the longer compilation times and I put most of my forward declarations in a single file at the start (and then a few in a second one later).
I am considering growing up and using .cpp files, but I am getting loads of errors, probably because I don't properly understand the compilation/linking process.
Am I right in thinking that all the included .h files are in one compilation unit and each of the .cpp files are in others, with each compilation unit needing all the header files to which it refers included?
My code is here: https://github.com/StagBeetle/Buttseqs but I expect someone knowledgeable can figure it out without looking at the code. To summarise, I moved the definition of two of my functions from the debug.h into a debug.cpp file, added the includes to header files (each with header guards) that it seemed to need, and now I have many of multiple definition errors.
Here are the first four errors out of about 50:
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `nullIntFunc(int)'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/Utility.h:21: first defined here
c:/program files (x86)/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `modes::encoderAllocator(int, int)'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1/functional:1829: first defined here
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `nullFunc()'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1/functional:1829: first defined here
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `scheduled::newEvent(scheduled::lOE::listOfEvents, std::function<void ()>, long)'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1/functional:1829: first defined here
Each one starts "In function "nullIntFunc(int)", despite the definition of that function simply being {;}
Each of them seems to claim the error is in forwarddec.h:274 and each (after the first) says the first definition is in functional:1829
What is going wrong here? Thanks in advance.
I have been working on a large project without .cpp files because I was fine with the longer compilation times and I put most of my forward declarations in a single file at the start (and then a few in a second one later).
I am considering growing up and using .cpp files, but I am getting loads of errors, probably because I don't properly understand the compilation/linking process.
Am I right in thinking that all the included .h files are in one compilation unit and each of the .cpp files are in others, with each compilation unit needing all the header files to which it refers included?
My code is here: https://github.com/StagBeetle/Buttseqs but I expect someone knowledgeable can figure it out without looking at the code. To summarise, I moved the definition of two of my functions from the debug.h into a debug.cpp file, added the includes to header files (each with header guards) that it seemed to need, and now I have many of multiple definition errors.
Here are the first four errors out of about 50:
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `nullIntFunc(int)'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/Utility.h:21: first defined here
c:/program files (x86)/arduino/hardware/tools/arm/bin/../lib/gcc/arm-none-eabi/5.4.1/../../../../arm-none-eabi/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `modes::encoderAllocator(int, int)'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1/functional:1829: first defined here
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `nullFunc()'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1/functional:1829: first defined here
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\sequencer.ino.cpp.o: In function `nullIntFunc(int)':
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch/forwarddec.h:274: multiple definition of `scheduled::newEvent(scheduled::lOE::listOfEvents, std::function<void ()>, long)'
C:\Users\Lynxwave\AppData\Local\Temp\arduino_build_328148\sketch\debug.cpp.o:c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1/functional:1829: first defined here
Each one starts "In function "nullIntFunc(int)", despite the definition of that function simply being {;}
Each of them seems to claim the error is in forwarddec.h:274 and each (after the first) says the first definition is in functional:1829
What is going wrong here? Thanks in advance.