Previously I was using Platform IO environment but recently I switched to esp-idf (version 4.4.1) environment. This will come with new opportunities and challenges. What I’m trying to do is making my own esp32 project with C++ (not C), and make use of some external C components. The problem is that the linker, not the compiler, can’t build my solution. The Espressif Build System with CMake is new for me and I guess that I do something wrong here. I've made the code as small as possible to get it back to the essence of the issue. Could anyone tell me what I’m missing here?
The error is as follow:
in function `app_main': …main/test.cpp:6: undefined reference to `say_hello()' collect2.exe: error: ld returned 1 exit status
CMakeLists.txt
Code: Select all
cmake_minimum_required(VERSION 3.8)
set(CMAKE_CXX_STANDARD 17)
set(EXTRA_COMPONENT_DIRS src include lib components)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(test)
Code: Select all
/* main program */
#include <stdio.h>
#include "my_component.h"
extern "C" void app_main(void) {
say_hello();
printf("app_main\n");
}
Code: Select all
idf_component_register(SRCS ${srcs} "test.cpp"
INCLUDE_DIRS ${include_dirs} "."
REQUIRES my_component)
Code: Select all
#include <stdio.h>
#include "my_component.h"
void say_hello(void) {
printf("Hello CPP\n");
}
Code: Select all
void say_hello(void);
Code: Select all
idf_component_register(SRCS "my_component.c" INCLUDE_DIRS ".")