Cant compile using stl files

magnomp
Posts: 13
Joined: Tue Sep 11, 2018 7:57 pm

Cant compile using stl files

Postby magnomp » Tue May 28, 2019 9:34 pm

I'm trying to compile a code that uses stl <map> but I'm getting this error:
fatal error: map: No such file or directory

I'm using latest esp-mdf

magnomp
Posts: 13
Joined: Tue Sep 11, 2018 7:57 pm

Re: Cant compile using stl files

Postby magnomp » Wed May 29, 2019 12:18 pm

Just to make sure it's not an error on my project, I did a copy of the development_kit/light sample project and simply added a

Code: Select all

#include <map>
to the light_example.c file, and then make -j4 flash, I got this output:

Code: Select all

$ make -j4 flash
Toolchain path: /opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gcc
Toolchain version: crosstool-ng-1.22.0-80-g6c4433a5
Compiler version: 5.2.0
Python requirements from D:/esp/esp-mdf/esp-idf/requirements.txt are satisfied.
CC build/main/light_example.o
CC build/mconfig/mconfig_chain.o
CC build/mdns/mdns.o
D:/m10smarthome/light/main/light_example.c:39:15: fatal error: map: No such file or directory
compilation terminated.

magnomp
Posts: 13
Joined: Tue Sep 11, 2018 7:57 pm

Re: Cant compile using stl files

Postby magnomp » Wed May 29, 2019 6:27 pm

Ok, just found out that I have to name the files as *.cpp if I want to use c++ stuff.
This seems obvious, but I used to code on esp-idf on PlatformIO and I could use c++ libraries and language features on .c files. I thought esp-idf build system compiled everything as c++ by default.

Also, it's woth to mention that after I renamed light_example.c to light_example.cpp I get a compile error on mlink_trigger.h line 83, whith is:
#ifdef __cplusplus
} // HERE
#endif /**< _cplusplus */

ESP_Bond
Posts: 51
Joined: Mon Apr 15, 2019 1:37 pm

Re: Cant compile using stl files

Postby ESP_Bond » Thu May 30, 2019 6:19 am

Functions that call C++ directly need to have the file format `cpp` or put `extern "C" in front of the function.

I suggest you: Write the function that needs to use the esp-idf interface in a `cpp` file, and put `extern "C" `. in front of the function. This can be called directly in c.

> Note: If you have questions, you can post the [issue](https://github.com/espressif/esp-mdf/issues) on github

Who is online

Users browsing this forum: No registered users and 35 guests