I'm trying to use the Mesh Development Framework within a C++ program. Unfortunately I'm not able to get past the most simple "get_started.c". I've renamed the get_started.c example to get_started.cpp, which breaks the compilation due to it using - presumably - the C++ compiler. I've tried wrapping the functions within extern "C", but this results in errors. Even when stripping out 95% of the code in get_started.cpp, I still end up with errors. Below is my current get_started,cpp, and the errors returned.
Would anyone be able to point me in the right direction to include C within my C++ code? I'm from an Arduino background where libraries are all C++ so I've not had problems like this before!
Many thanks.
get_started.cpp
Code: Select all
/*
* ESPRESSIF MIT License
*
* Copyright (c) 2018 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on all ESPRESSIF SYSTEMS products, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#include "mdf_common.h"
#include "mwifi.h"
// #define MEMORY_DEBUG
extern "C"
{
static int g_sockfd = -1;
static const char *TAG = "get_started";
void app_main()
{
//nothing yet
}
void tcp_client_write_task(void *arg)
{
mdf_err_t ret = MDF_OK;
char *data = MDF_CALLOC(1, MWIFI_PAYLOAD_LEN);
MDF_LOGI("TCP client write task is running");
while (mwifi_is_connected())
{
}
}
}
Code: Select all
Python requirements from /Users/elijah/esp-mdf/esp-idf/requirements.txt are satisfied.
In file included from /Users/elijah/esp-mdf/components/mcommon/include/mdf_common.h:59:0,
from /Users/elijah/esp/get-started/main/get_started.cpp:25:
/Users/elijah/esp/get-started/main/get_started.cpp: In function 'void tcp_client_write_task(void*)':
/Users/elijah/esp-mdf/components/mcommon/include/mdf_mem.h:111:12: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
ptr; \
^
/Users/elijah/esp/get-started/main/get_started.cpp:50:18: note: in expansion of macro 'MDF_CALLOC'
char *data = MDF_CALLOC(1, MWIFI_PAYLOAD_LEN);
^
/Users/elijah/esp/get-started/main/get_started.cpp:49:15: warning: unused variable 'ret' [-Wunused-variable]
mdf_err_t ret = MDF_OK;
^
/Users/elijah/esp/get-started/main/get_started.cpp:50:11: warning: unused variable 'data' [-Wunused-variable]
char *data = MDF_CALLOC(1, MWIFI_PAYLOAD_LEN);
^
/Users/elijah/esp/get-started/main/get_started.cpp: At global scope:
/Users/elijah/esp/get-started/main/get_started.cpp:34:16: warning: 'g_sockfd' defined but not used [-Wunused-variable]
static int g_sockfd = -1;
^
make[1]: *** [get_started.o] Error 1
make: *** [component-main-build] Error 2
make: *** Waiting for unfinished jobs....