Need help for building code with ESP-IDF & CMake & Eclipse

kenn.tran
Posts: 9
Joined: Thu May 14, 2020 2:09 pm

Need help for building code with ESP-IDF & CMake & Eclipse

Postby kenn.tran » Thu May 14, 2020 2:51 pm

Hi everyone,

I'm new here - not totally new, I've done project with ESP32 on Arduino IDE but now I'm trying to re-factor everything with ESP-IDF and it requires knowledge in different fields I didn't know (e.g CMake).

Now I have a issue with struct in C. I cannot pass the struct which I have defined in [main.h] and used in [main.c] call from another file in [component/sensor.c].

Please help me!!! Here is the example of my project:

[tree of my project]

Code: Select all

project:
 - CMakeList.txt
 - component.mk
 - main:
     - main.h
     - main.c 
 - component:
     - CMakeList.txt
     - component.mk
     - sensor.c
     - include:
         - sensor.h
[main.h]

Code: Select all

 
  typedef struct ax
{
uint8_t a;
uint16_t b;
float x;
}ax;
 
 ax ax_ms[500];
[sensor.h]

Code: Select all

#include "main.h"

void ex_func(uint8_t x, ax *ax_ms);
[sensor.c]

Code: Select all

#include "sensor.h"
void ex_func(uint8_t x, ax *ax_ms)
{
   doing something;
}
[main.c]

Code: Select all

#include "main.h"

ex_func( x, &ax_ms );




[CMakeList.txt - project folder]

Code: Select all

include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(example)
[component.mk - project folder]

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := components/include 
COMPONENT_SRCDIRS := components
[CMakeList.txt - component folder]

Code: Select all

set(COMPONENT_ADD_INCLUDEDIRS include ../main)
set(COMPONENT_SRCS "sensor.c")

register_component()
[component.mk - component folder]

Code: Select all

COMPONENT_ADD_INCLUDEDIRS := include ../main
When I run "build", I always get the error message "unknown type name `ax `".
Btw, I use Eclipse with ESP-IDF on Windows10.

Thanks

kenn.tran
Posts: 9
Joined: Thu May 14, 2020 2:09 pm

Re: Need help for building code with ESP-IDF & CMake & Eclipse

Postby kenn.tran » Fri May 15, 2020 7:30 am

I got it work...

I defined the struct in [sensor.h] and initialize the struct array in [main.c].

Besides that I change the way defined struct from

typedef struct ax{
...
};

to be

typedef struct{
...
}ax;

Who is online

Users browsing this forum: Google [Bot], MicroController and 118 guests