Compile Errors Make No Sense

I’ve been staring at this all evening, and I can’t figure out where I’m going wrong. I originally tried to compile in Dev, and got the “build didn’t produce binary error: Command failed:/…”. I then copied the files to a new project in Build, and got these errors,

…/…/…/build/target/user/platform-6/libuser.a(sprinklers.o):(.data.shouldSync+0x0): multiple definition of shouldSync' ../../../build/target/user/platform-6/libuser.a(Valves.o):(.data.shouldSync+0x0): first defined here ../../../build/target/user/platform-6/libuser.a(sprinklers.o):(.data.cumDays+0x0): multiple definition ofcumDays’
…/…/…/build/target/user/platform-6/libuser.a(Valves.o):(.data.cumDays+0x0): first defined here
…/…/…/build/target/user/platform-6/libuser.a(sprinklers.o): In function loop': /src/sprinklers.cpp:21: multiple definition ofstartTime’
…/…/…/build/target/user/platform-6/libuser.a(Valves.o):/src/Valves.cpp:11: first defined here
…/…/…/build/target/user/platform-6/libuser.a(sprinklers.o):(.data.names+0x0): multiple definition of names' ../../../build/target/user/platform-6/libuser.a(Valves.o):(.data.names+0x0): first defined here ../../../build/target/user/platform-6/libuser.a(sprinklers.o): In functionloop’:
/src/sprinklers.cpp:21: multiple definition of `allValves’
…/…/…/build/target/user/platform-6/libuser.a(Valves.o):/src/Valves.cpp:11: first defined here
collect2: error: ld returned 1 exit status
make: *** [e6a1e2cfc446005ad063f490457acf1e8ad698d2e8aab327d81982de3f72.elf] Error 1

There a bunch of “multiple definition” errors, but there aren’t multiple definitions in my code, so I have no idea what’s wrong. Any ideas?

Check carefully all your header files and the inclusions of them in all .cpp files. Ensure also to have the proper #ifndef in place in each header file.

FYI, you get a verbose compiler report compiling with the CLI, so (in the future) you don’t need to copy to Build if you get obfuscated compiler errors in Dev… just go to the command line and compile.

A shot in the dark here: are you creating a global variable in a header file (which also gets used in an implementation file)?

if so, they should be created in the implementation file and extern in the header.

I’m not sure if that was the problem, but it was something like that. All my variables were class members. I’m still not clear on the overall structure of C++ projects, and what goes in what file. I’m used to Objective-C, which uses a #import that I think insures that things don’t get double included.

I looked into that, but the instructions on how to do that were unclear to me. I see the command to use in the docs, but not the whole process; like what directory do I need to be in when I issue the command? The example only shows compiling a .ino file, but my project in Dev contains more files than that as well as a library dependency. I also don’t know if the process has changed in the latest update of Dev.

you can be 1) in the directory with the *.ino file:

particle compile photon

the binary gets created in that folder.

or 2) in the folder above

particle compile photon <directoryName>

and the binary ends up in the folder above.

1 Like

For building a project with CLI you just cd into the project base directory (the one with project.properties for 2.0 projects) and execute

particle compile [ photon | electron | bluz | ... ] . [--target 0.6.0] [--saveTo firmware.bin]

the expressions in brackets are options or optional and the dot in between stands for current directory


@BulldogLowell was quicker this time :wink:

Does “above” mean the folder you mention above in your post (that would be src since that’s where the .ino file is), or do you mean above in the folder tree (that would be the top folder, the one with the project’s name)? I’ve tried both, and I get this error.

Including:
/Users/ricdelmar/Desktop/_Particle_Projects/Photon Sketches/SprinklerControl/src/Sprinklers.h
/Users/ricdelmar/Desktop/_Particle_Projects/Photon Sketches/SprinklerControl/src/SprinklerControl.ino
/Users/ricdelmar/Desktop/_Particle_Projects/Photon Sketches/SprinklerControl/src/Sprinklers.cpp
attempting to compile firmware
Compile failed. Exiting.
In file included from SprinklerControl.cpp:7:0:
Sprinklers.h:3:24: fatal error: HttpClient.h: No such file or directory
#include “HttpClient.h”

But my project.properties file does have “dependencies.HttpClient=0.0.5” I’ve tried the include using either “HttpClient.h” or with angle brackets, both give the same error.

sorry! I’m not using the Particle Project file structure (yet)!!!

@ScruffR ?

@Ric, as I said:

Yeah, as I said in my last response to BulldogLowell, I tried that. I issued the following command from my top directory (SprinklerControl in my case, the topmost folder I see in Dev, the one that contains src, project.properties, .DS_Store, and README.md)

particle compile photon

Is that correct? I wasn’t sure what you were saying about the dot. Do I include that? I just want the .bin file to end up in the same place it would if I compiled from Dev. Sorry for my obtuseness, I’m not very familiar with unix type command line syntax.

I also tried this in another project that compiles fine in Dev, and got the same error about “HttpClient.h” not existing, even though it does.

Yup, I’d write that exactly that way

particle compile photon .

(with the dot)

I have never tried it without tho’ :blush:

But just as the double dot (..) stands for the parent directory, does the single dot (.) stand for the current directory.
Hence on Windows you’ll always get the two “directories” reported when you executw a dir command in cmd

BTW, what’s the contents of your project.properties file?
It needs to contain this line

dependencies.HttpClient=0.0.5

But the library files should not be present in your project folder.

Hi @Ric

I can see you are getting lots of good advice here but I just wanted to point out that when I get redefinition warnings like that, most of the time it is because I forget to add a #pragma once or #ifdef macro to a header file and it is being included more than once.

The project.properties file looks like this,

name=SprinklerControl
dependencies.HttpClient=0.0.5

The directory tree is,

That advice of @bko is just as sound (but usually with #ifndef) as the one from your very first response you got

Have you confirmed that everything is in order that way?

I don’t know. I did wrap the .h file in a #ifndef block (which didn’t get rid of the error), but the whole point of me going to the CLI was to get a complete error report. I assume that there is something still wrong with my overall structure, but the fact that the error I get is a bogus one about the library, and doesn’t point out what the real problem is, defeats the point of the whole exercise. In all my messing around with the code last night, I have changed things, so the program is not the same as the one that gave me the errors reported in my original question.

In any case, I’ve written a new version in plain old C, with just a .h and a .ino file, and that one works properly. I’ll look around to see if I can find some good sources for learning C++ program structure.