I'm trying to add this library to my ESP-IDF application in Visual Studio Code (not using PlatformIO).
Here the step I did:
components/components/
folder in the root of my projectmain.cpp
:#define EVE_CS GPIO_NUM_47
#define EVE_PDN GPIO_NUM_11
#define EVE_SCK GPIO_NUM_19
#define EVE_MISO GPIO_NUM_20
#define EVE_MOSI GPIO_NUM_21
#define EVE_NHD_50
#include <stdio.h>
#include "../components/components/FT800-FT813-5.x/src/EVE.h"
void app_main(void)
{
EVE_init_spi();
}
Now, the linker fails:
/home/mark/myproject/main/main.c:14:(.text.app_main+0x3): undefined reference to `EVE_init_spi'
The README of the library says:
The platform the code is compiled for is automatically detected thru compiler flags in EVE_target.h
Indeed, inside EVE_target.h
I see:
#if defined (ESP_PLATFORM)
#include "EVE_target/EVE_target_ESP32.h"
#endif /* ESP_PLATFORM */
and ESP_PLAFTORM
is defined to 1 (I can see it hovering the mouse and a tooltip appears). Then I followed EVE_target_ESP32.h
and also there the platform is defined. But the implementation of void EVE_init_spi(void);
is inside EVE_target.c
and inside that file ESP_PLAFORM
is not defined.
Hence, all the code related to ESP32 (and even to other platforms) is not enabled and I guess this is the cause of the linker error.
Since I put the library folder inside the components
directory I was expecting it is already handled by CMake. By the way, these are the top level and the code level CMakeLists.txt files:
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(myproject)
and
idf_component_register(SRCS "main.c"
INCLUDE_DIRS ".")
I found out the ESP_PLATFORM
is defined by the Ninja script when invoking the compiler:
DEFINES = -DESP_PLATFORM
What else should I set in order to make ESP_PLATFORM
available also for EVE_target.c
?
The component is missing a CMakeLists.txt
file to interact with the ESP-IDF build system.
Please add a CMakeLists.txt file in your FT800-FT813-5.x
directory, according to the ESP-IDF build system component documentation. This contains the idf_component_register()
call and will make sure that the source files are built and the include paths are set correctly, among other things.
Afterwards, you need to change the call in the main
component's CMakeLists.txt
file to:
idf_component_register(SRCS "main.c"
INCLUDE_DIRS "."
PRIV_REQUIRES "FT800-FT813-5.x")
I'd also suggest to remove the double components
directory, I'm not sure if the build system still recognizes the component in the current structure.