SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.52k stars 491 forks source link

CPP linkage for SPIFFS #344

Open MartianWearables opened 7 years ago

MartianWearables commented 7 years ago

It seems that cpp linkage was not considered when porting the SPIFFS module? I added the necessary `

ifdef __cplusplus

extern "C" { ... ` around relevant methods in the esp_spiffs.h file, which allowed it to compile.

Spiffs is able to init and mount, but int fd = open("other.txt", O_WRONGLY|O_CREATE, 0); fails with "Error opening file". Also, SPIFFS_info returns total = -15311 bytes and used = 0 bytes.

Any ideas on how to get SPIFFS working from inside my cpp class?

Cheers

MartianWearables commented 7 years ago

I solved the problem: In addition to adding the extern "C" to both included spiffs header files, I had to make sure not to use the posix "read()" or "close()" functions, and they conflicted with those provided by the lwip library. Note the the spiffs example included with esp-open-rtos does not use the SPIFFS_write(), even though it is available and functional. I think the SPIFFS example should be changed to include both posix write() and SPIFFS_write. Also, the posix file manipulation api's should be made intercompatible.

Cheers

lhartmann commented 7 years ago

Several extras are missing that, httpd included.

I wrote a batch check/fix script. Not perfect, but does the job. http://pastebin.com/WXfZDSQL

# Go to the root of the SDK
cd esp-open-rtos
# Get a list of headers missing extern "C" under current directory
cppchk.sh
# If you feel safe, then patch all headers
cppchk.sh --fix