Errors compiling

I am trying to compile a huge program I have been porting from arduino to photon.

I was using web ide for checking examples and small parts of code which I wasn’t sure they would work and particle dev for my whole program.

It seems to compile fine until I added the last 2 or 3 files (http library) then I started to get (just compiling, I never tried to upload code from here) the message: “build didn’t produce any binary bla bla bla.” so I tried to compile locally in a virtual machine I created with ubuntu and with all CLI tools instaled.

I uploaded the firmware version of a photon device a couple of weeks ago with this virtual machine so I guess everything is installed fine.

So this is my folder structure:

I copied my program inside photonSketch folder and run:
particle compile photon .
and I get a bunch of errors. First line is:

I don’t know what this means.

Then I get a list with all my files: Including:…

And then tons of warnings from HttpClient library and TimeAlarms library. Both included in my sketch and both in the same folder.

After that, I get the list of errors. First declared here things and so on.

In this point, I guess I have to concepts mismatched.

I will try to explain the errors I get and how I have declared all elements.

For example, I have a .h file in which I have declared a structure to contain some arrays and data. I want to use this structure in all my functions as an argument, something like this:

For this, I have declared my structure in this .h file and then I have imported it in all files which have functions which use this struct.

I get no errors about that, so I think it is ok.

But, following the same pattern. I have an array which contains 5 elements. It is declared in the same .h file as follows:

Those PIN_REL_X are defined right before.

I am getting this errors for this array:

../../../build/target/user/platform-6/libuser.a(default.o):(.data.relayArrayPins+0x0): multiple definition of `relayArrayPins' ../../../build/target/user/platform-6/libuser.a(Main.o):(.data.relayArrayPins+0x0): first defined here

I can swear I haven’t declared this array in other file.

My params.h starts:

#ifndef __PARAMS_H__
#define __PARAMS_H__

and ends:

Other example is about DS18B20 and dht classes. I have 2 files: sensor.h and sensor.cpp to store sensor related functions (getTemp, getHum…)

In my .h I have these lines before function declarations:

DS18B20 ds18b20(D2); DHT dht;

and then in my functions (in .cpp files) I use them like: dht.getTemp… or whatever.

I also get “multiple declaration in…”

I have a file called loop.cpp/loop.h in which I call a getTemperature function which is in sensor.cpp/sensor.h and contains ds18b20 instance. Maybe I have something wrong with my code structure.

I’d prefer not to post my whole code here since it is not mine and I am just helping to other person who prefers not to do it. But if you think it is mandatory, I will try to upload just enough examples to see my problem.

If you have multiple modules that implement the same variable (e.g. relayArrayPins[]), each module will have its own copy of such variable and hence you’ll get this linker error.
Having that #ifndef or #pragma once in place will not prevent this error, since each module is compiled seperately, having only its own copy, but on linkage it’ll fail.

Maybe you “inherit” that via an #include.

If you want to use one copy of relayArrayPins[] across several modules, you’re only allowed to implement that once and all other modules should just have an extern uint8_t relayArrayPins[].
Hence the actual definition should not be in a header, but in a .cpp file.

That SerialCommand.js error has not really anything to do with your project but rather with a not fully installed CLI.

If you can’t upload the code, you should at least upload more of the error messages, especially the context of one particular error (including related waringns & notes just before and after the respective error).

1 Like

I see. I will try to fix all the already defined errors and as soon as I have the others errors/warnings I will try to upload everything I can.

Thank you!

EDIT: Well… surprisingly, all my errors were gone when I fixed the repeated variables. Now it compiles fine, I don’t see warnings (I guess the tool doesn’t show them since some of them come from libraries I haven’t touch)

Next step :Learn how to update my bin file and start debugging. Also I will need to check the error comming from SerialCommand.js

Try updating your CLI, that might fix things, if you hadn’t already done so.

I tried to update, I already have the latest version. How can I reinstall particle-cli? removing folder and installing again?

I have read about downgrading node version to 4.4.4 (already done) and reinstall particle-cli