Error: 404. Please try again

I keep getting this or “Error: Could not compile. Please review your code”. I’m trying to create a class that would control an irrigation system but I cannot seem to get it to work. When it was just the .ino file it worked fine but as soon as I added a header and implementation file it stopped working. I’m a little confused on where the object should be created. In the reference guide, they create it after the class declaration but wouldn’t it make more sense to create in the main project file? I think it might also have to do with the libraries I am including and to which files I should have includes. I have tried both the web and desktop IDE and nothing has worked. Any helped would be greatly appreciated. Here is a link to the project:

if you View Raw after compiling fails, you’ll find at the end:

../../../build/target/user/platform-6-mlibuser.a(irrigationclass_v2.o):(.bss._ZN16Irrigation_Class12myIrrigationE+0x0): multiple definition of `Irrigation_Class::myIrrigation'
../../../build/target/user/platform-6-mlibuser.a(irrigation.o):(.bss._ZN16Irrigation_Class12myIrrigationE+0x0): first defined here
../../../build/target/user/platform-6-mlibuser.a(irrigationclass_v2.o): In function `$d':
irrigationclass_v2.ino:13: multiple definition of `lcd'
../../../build/target/user/platform-6-mlibuser.a(irrigation.o):src/irrigation.cpp:8: first defined here
collect2: error: ld returned 1 exit status

The problem is that you have declared a variable in your .h file:

irrigation myIrrigation;

You can only declare a class extern in a .h file included by multiple files, as irrigation.h is (from irrigation.cpp and irrigation-class-v2.ino).

extern irrigation myIrrigation;

Then declare it once, probably in irrigation.cpp:

irrigation myIrrigation;

That helped verify the code, although now the photon crashes when I flash the code.

You need two-phase construction. Right now, you’re setting everything up in the constructor. Since you have a global C++ object, this can cause problems.

You can’t call Particle.function or delay, and probably can’t initialize your LCD display at global object construction time.

Basically you need to the bulk of the code in the constructor into a new method irrigation::setup().

Then from the real setup() call myIrrigation.setup().

1 Like

This is what I have now:
and I’m back to getting a could not compile error. I’m not sure if its because where I’m creating the myIrrigation object or something with the Irrigation_Class namespace. If I View Raw I still have "multiple definition of ‘lcd’ but I don’t know if that’s because of object or something else I’m missing

You should just get rid of namespace Irrigation_Class because it doesn’t serve a particularly useful purpose and it just complicates things.

However you need to fix the duplicate definition of lcd because it’s happening for the exact same reason that irrigation myIrrigation caused the same error. The fix is the same.


That worked! Thanks!

1 Like