CLionArduinoPlugin icon indicating copy to clipboard operation
CLionArduinoPlugin copied to clipboard

Got build error when starting using custom struct types

Open morozovcookie opened this issue 5 years ago • 0 comments

Hello! I Got an error build when I changed my code and adding struct. I trying to build this stuff with Arduino IDE and all works fine.

Sample of code:

#include <Arduino.h>

struct custom_type_t
{
    int val;
};

void print_custom_type(const custom_type_t&);

void
setup() {
    Serial.begin(9600);
}

void
loop() {
    custom_type_t var { 10 };
    print_custom_type(var);
    delay(1000);
}

void
print_custom_type(const custom_type_t& arg)
{
    Serial.println(arg.val);
}

When I buiding project into CLion I got error like this:

/Users/.../Project/cmake-build-debug/UsingStruct_using_struct.ino.cpp:13:31: error: 'custom_type_t' does not name a type
  void print_custom_type(const custom_type_t& arg) ;

And here is generated file (UsingStruct_using_struct.ino.cpp):

// automatically generated by arduino-cmake
#line 1 "/Users/.../UsingStruct/using_struct.ino"
#include <Arduino.h>
//======================================================================================================================
#line 6 "/Users/.../UsingStruct/cmake-build-debug/UsingStruct_using_struct.ino.cpp"
#include "Arduino.h"

//=== START Forward: /Users/.../UsingStruct/using_struct.ino
 void setup() ;
 void setup() ;
 void loop() ;
 void loop() ;
 void print_custom_type(const custom_type_t& arg) ;
 void print_custom_type(const custom_type_t& arg) ;
//=== END Forward: /Users/.../UsingStruct/using_struct.ino
#line 1 "/Users/.../UsingStruct/using_struct.ino"


struct custom_type_t
{
    int val;
};

void print_custom_type(const custom_type_t&);

void
setup() {
    Serial.begin(9600);
}

void
loop() {
    custom_type_t var { 10 };
    print_custom_type(var);
    delay(1000);
}

void
print_custom_type(const custom_type_t& arg)
{
    Serial.println(arg.val);
}

It is looks like that problem in arduino-cmake generator, because it is write a function definition with custom type which was not declared before.

OS: macOS Catalina v10.15.4 CLion ver.: CLion 2020.1.1 Build #CL-201.7223.86, built on April 29, 2020 Plugin ver.: 1.5.2

morozovcookie avatar May 19 '20 09:05 morozovcookie