In the meantime I went a step further - but it's still not solved.
I now have the following directory structure inside my project dir:
My
CMakeLists.txt in the base project dir looks like follows:
Code: Select all
cmake_minimum_required( VERSION 3.10 )
set( CMAKE_C_STANDARD 11 )
set( CMAKE_CXX_STANDARD 17 )
if ( ${ESP_PLATFORM} )
FILE( TO_CMAKE_PATH "$ENV{IDF_PATH}" idf_path )
include( ${idf_path}/tools/cmake/project.cmake )
set( EXTRA_COMPONENT_DIRS
MyWifi )
# Projektname:
project( MyProject )
else() # ! ESP_PLATFORM
# empty...
endif()
The
CMakeLists.txt in the
main directory is this:
Code: Select all
cmake_minimum_required( VERSION 3.10 )
set( CMAKE_C_STANDARD 11 )
set( CMAKE_CXX_STANDARD 17 )
FILE( GLOB_RECURSE my_sources *.cpp *.h *.hpp )
FILE( TO_CMAKE_PATH "$ENV{IDF_PATH}" idf_path )
if ( ${ESP_PLATFORM} )
idf_component_register(
SRCS ${my_sources}
INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}"
"${idf_path}/components"
"${idf_path}"
REQUIRES MyWifi )
endif()
The
CMakeLists.txt in the
MyWifi directory is this:
Code: Select all
cmake_minimum_required( VERSION 3.10 )
set( CMAKE_C_STANDARD 11 )
set( CMAKE_CXX_STANDARD 17 )
FILE( GLOB_RECURSE my_sources *.cpp *.h *.hpp )
FILE( TO_CMAKE_PATH "$ENV{IDF_PATH}" idf_path )
if ( ${ESP_PLATFORM} )
idf_component_register(
SRCS ${my_sources}
INCLUDE_DIRS "${CMAKE_CURRENT_LIST_DIR}"
"${CMAKE_SOURCE_DIR}/include"
"${CMAKE_SOURCE_DIR}"
"${idf_path}/components"
"${idf_path}" )
endif()
In every of the above directories there is an empty
component.mk
The following source files exist:
Code: Select all
sdkconfig
version.txt
include/MyWifi.hpp
include/Singleton.hpp
main/main.cpp
MyWifi.cpp
Here is
include/Singleton.hpp:
Code: Select all
#ifndef __MY__SINGLETON_H__
#define __MY__SINGLETON_H__
namespace NS1 {
namespace SubNS1 {
template < typename T >
class CSingleton
{
public:
template < typename... Args >
static constexpr T& Inst( Args... args_ ) {
static T instance( std::forward< Args >(args_)... );
// damit bei Optimierung die Methode nicht wegrationalisiert wird:
volatile int dummy{};
return instance;
}
protected:
T() = default;
~T() = default;
private:
T( const T& ) = delete;
T& operator=( const T& ) = delete;
T( const T&& ) = delete;
T& operator=( const T&& ) = delete;
}; // END_CLASS CSingleton
}
}
#endif
And the
include/MyWifi.hpp:
Code: Select all
#ifndef __MY__MYWIFI_H__
#define __MY__MYWIFI_H__
#include "Singleton.hpp"
namespace NS1 {
namespace SubNS1 {
class CMyWifi final
: public CSingleton<CMyWifi>
{
public:
void Init( void );
void Connect( void );
void Scan( void );
void TaskKeepAlive( void* pParam_ );
private:
CMyWifi()
: CSingleton() {
}
}; // END_CLASS CMyWifi
}
}
static NS1::SubNS1::CMyWifi& g_WiFi = SD::MOC::CMyWifi::Inst();
#endif
The
MyWifi/MyWifi.cpp is currently only a nearly empty class:
Code: Select all
#include "MyWifi.hpp"
#include <freertos/FreeRTOS.h>
#include <freertos/event_groups.h>
#include <freertos/task.h>
#include <esp_event.h>
#include <esp_log.h>
#include <esp_system.h>
#include <esp_wifi.h>
//#include <esp_wpa2.h>
//#include <nvs_flash.h>
#define WIFI_CONNECT_SSID "MySSID"
#define WIFI_CONNECT_PASSWD "MySSIDPasswd"
#define WIFI_AP_SSID "MyAPSSID"
#define WIFI_AP_PASSWD "MyAPSSIDPasswd"
// FreeRTOS event group to signal when we are connected and
// ready to make a request:
static EventGroupHandle_t WifiEventGroup;
// The event group allows multiple bits for each event, but we only care about
// one event - are we connected to the AP with an IP?
const int CONNECTED_BIT = BIT0;
namespace NS1 {
namespace SubNS1 {
void CMyWifi::Init()
{
tcpip_adapter_init();
WifiEventGroup = xEventGroupCreate();
ESP_ERROR_CHECK( esp_event_loop_create_default() )
wifi_init_config_t wifiInitCfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&wifiInitCfg) );
}
void CMyWifi::Connect()
{
}
void CMyWifi::Scan()
{
}
void TaskKeepAlive( void *pParam_ )
{
for ( ; ; ) {
}
}
}
}
main/main.cpp is this:
Code: Select all
#include "MyWifi.hpp"
#include <esp_err.h>
//#include <nvs.hpp>
//#include <nvs_flash>
#ifdef __cplusplus
extern "C" {
#endif
void app_main( void )
{
// Initialize NVS
esp_err_t ret;
ret = nvs_flash_init();
if ( ret == ESP_ERR_NVS_NO_FREE_PAGES ||
ret == ESP_ERR_NVS_NEW_VERSION_FOUND ) {
ESP_ERROR_CHECK( nvs_flash_erase() );
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
//g_WiFi.Init();
}
#ifdef __cplusplus
} // extern "C"
#endif
I'm on Windows 10 Pro and try to compile it with esp-idf v4.0.1 via command line (%IDF_PATH%\export.bat has been executed):
After a longer compilation of the esp-idf itself it came to my directory and it doesn't matter if I use
#include <nvs.hpp> or
#include <nvs.h> or if I add
#include <nvs_flash.h> I always get errors, that the include files could not be found:
Code: Select all
[2/12] cmd.exe /C "cd /D D:\Prog\MyProject\build\bootloader && D:\Prog\ESP32\esp-idf\Tools\tools\cmake\3.13.4\bin\cmake.exe --build ."
ninja: no work to do.
[3/10] ccache D:\Prog\ESP32\esp-idf\Tools\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -Iconfig -I../main -I../include -I../ -ID:/Prog/ESP32/esp-idf/v4/components -ID:/Prog/ESP32/esp-idf/v4 -ID:/Prog/ESP32/esp-idf/v4/components/newlib/platform_include -ID:/Prog/ESP32/esp-idf/v4/components/freertos/include -ID:/Prog/ESP32/esp-idf/v4/components/heap/include -ID:/Prog/ESP32/esp-idf/v4/components/log/include -ID:/Prog/ESP32/esp-idf/v4/components/soc/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/soc/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_rom/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_common/include -ID:/Prog/ESP32/esp-idf/v4/components/xtensa/include -ID:/Prog/ESP32/esp-idf/v4/components/xtensa/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/driver/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_ringbuf/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_event/include -ID:/Prog/ESP32/esp-idf/v4/components/tcpip_adapter/include -ID:/Prog/ESP32/esp-idf/v4/components/lwip/include/apps -ID:/Prog/ESP32/esp-idf/v4/components/lwip/include/apps/sntp -ID:/Prog/ESP32/esp-idf/v4/components/lwip/lwip/src/include -ID:/Prog/ESP32/esp-idf/v4/components/lwip/port/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/lwip/port/esp32/include/arch -ID:/Prog/ESP32/esp-idf/v4/components/vfs/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_wifi/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_wifi/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_eth/include -ID:/Prog/ESP32/esp-idf/v4/components/efuse/include -ID:/Prog/ESP32/esp-idf/v4/components/efuse/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/app_trace/include -I../MyWifi -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -Wno-parentheses -Wno-sizeof-pointer-memaccess -Wno-clobbered -Wno-format-overflow -Wno-stringop-truncation -Wno-misleading-indentation -Wno-cast-function-type -Wno-implicit-fallthrough -Wno-unused-const-variable -Wno-switch-unreachable -Wno-format-truncation -Wno-memset-elt-size -Wno-int-in-bool-context -fstack-protector-all -std=gnu++11 -fexceptions -fno-rtti -D_GNU_SOURCE -DIDF_VER=\"v4.0.1-316-g48ea44f3d-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -std=gnu++17 -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\main.cpp.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -c ../main/main.cpp
FAILED: esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj
ccache D:\Prog\ESP32\esp-idf\Tools\tools\xtensa-esp32-elf\esp-2019r2-8.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -Iconfig -I../main -I../include -I../ -ID:/Prog/ESP32/esp-idf/v4/components -ID:/Prog/ESP32/esp-idf/v4 -ID:/Prog/ESP32/esp-idf/v4/components/newlib/platform_include -ID:/Prog/ESP32/esp-idf/v4/components/freertos/include -ID:/Prog/ESP32/esp-idf/v4/components/heap/include -ID:/Prog/ESP32/esp-idf/v4/components/log/include -ID:/Prog/ESP32/esp-idf/v4/components/soc/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/soc/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_rom/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_common/include -ID:/Prog/ESP32/esp-idf/v4/components/xtensa/include -ID:/Prog/ESP32/esp-idf/v4/components/xtensa/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/driver/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_ringbuf/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_event/include -ID:/Prog/ESP32/esp-idf/v4/components/tcpip_adapter/include -ID:/Prog/ESP32/esp-idf/v4/components/lwip/include/apps -ID:/Prog/ESP32/esp-idf/v4/components/lwip/include/apps/sntp -ID:/Prog/ESP32/esp-idf/v4/components/lwip/lwip/src/include -ID:/Prog/ESP32/esp-idf/v4/components/lwip/port/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/lwip/port/esp32/include/arch -ID:/Prog/ESP32/esp-idf/v4/components/vfs/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_wifi/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_wifi/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/esp_eth/include -ID:/Prog/ESP32/esp-idf/v4/components/efuse/include -ID:/Prog/ESP32/esp-idf/v4/components/efuse/esp32/include -ID:/Prog/ESP32/esp-idf/v4/components/app_trace/include -I../MyWifi -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -nostdlib -Wall -Werror=all -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -Wno-parentheses -Wno-sizeof-pointer-memaccess -Wno-clobbered -Wno-format-overflow -Wno-stringop-truncation -Wno-misleading-indentation -Wno-cast-function-type -Wno-implicit-fallthrough -Wno-unused-const-variable -Wno-switch-unreachable -Wno-format-truncation -Wno-memset-elt-size -Wno-int-in-bool-context -fstack-protector-all -std=gnu++11 -fexceptions -fno-rtti -D_GNU_SOURCE -DIDF_VER=\"v4.0.1-316-g48ea44f3d-dirty\" -DGCC_NOT_5_2_0 -DESP_PLATFORM -std=gnu++17 -MD -MT esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -MF esp-idf\main\CMakeFiles\__idf_main.dir\main.cpp.obj.d -o esp-idf/main/CMakeFiles/__idf_main.dir/main.cpp.obj -c ../main/main.cpp
../main/main.cpp:4:10: fatal error: nvs.h: No such file or directory
#include <nvs.h>
^~~~~~~
compilation terminated.
So in principal: isn't it not possible to program in C++ for ESP-IDF? Or what's the problem?