Go Down

Topic: Arduino CMake problem with includes (Read 1 time) previous topic - next topic

Marius

I have just converted a more complex sketch to use CMake. It would seem that the header file is not included at the right time as the declarations are not found in scope. The Arduino IDE will include the header files at the top of the CPP file that is generated and then compile. This way all declarations are in scope. With CMake I don't get this. Any advise please?
 
Rather people think you to be a fool than you open your mouth and confirm it.

Aeturnalus

In C/C++, you need to actually declare functions before calling them.  The Arduino preprocessor lets you cheat and put functions wherever by automatically pushing a pile of declarations to the top of the file - if your CMake doesn't do this, you'll have to add in declarations yourself.

For example:

Arduino:
Code: [Select]

void setup() {}
void loop() { foo(); }
void foo() {}

This works even though foo is undeclared before loop() because Arduino pushes a void foo(); on top of everything. 
Standard C/C++:
Code: [Select]

void foo(); // <-- important

void setup() {}
void loop() {foo();}
void foo() {}

Declarations need to come first.

Including header files at the top is your job.  #include exists for a reason, after all.  CMake will not, unless you tell it to, automatically add #include lines into your code.

Marius

I get what you are saying and I am used to doing it like that. I was under the impression the the CMake for Arduino code actually did just that ( the same as the Arduino IDE ). It would concat the .c, .pde, . cpp files and place the header files at the top of the whole lot.
Not a problem, then I know what to do to fix the problem.
I understand that there is a sketch converter underway - I wonder how this problem will be addressed?
Rather people think you to be a fool than you open your mouth and confirm it.

Aeturnalus

I'm not too sure what the CMake build option actually does right now, but I always thought that the CMake system was supposed to be a way to avoid the limitations of the Arduino IDE (especially the includes), and allow a more C/C++ style development environment. 

However, I'm a bad reference - I switched to Eclipse for AVR development about a year ago, and have only opened the IDE to test if my suggestions for the forum compile.

Massimo Banzi

Marius

where did you find the CMake code?
It's not something that we have released therefore there is no support for it.. The original author is the best place where to ask.

m

Marius

On the playground under Development Tools/other there is reference to this link
https://github.com/queezythegreat/arduino-cmake

Rather people think you to be a fool than you open your mouth and confirm it.

Go Up