cancel
Showing results for 
Search instead for 
Did you mean: 

I am new to CubeIDE and have created a c++ project. I had the system generate the code and renamed main.c to main.cpp. I then put a #include <string> in the main and I get a fatal error during the build: "string: no such file or directory."

DDurk.1
Associate II

This is running on Linux and I created a test program with the same include and compiled it with g++ without issue.

I think I need to tell CudeIDE where the standard libraries are located? If that is so, Where do I find them?

Thanks!!

1 ACCEPTED SOLUTION

Accepted Solutions

#include <string.h> 

JW

View solution in original post

5 REPLIES 5

#include <string.h> 

JW

TDK
Guru

CubeIDE uses GCC under the hood. Show the full error message. Perhaps you're not in a C++ source file. How are you creating the project?

<string> is the correct library. Or rather, it is a C++ library which is separate from the C library string.h.

https://www.cplusplus.com/reference/string/

If you feel a post has answered your question, please click "Accept as Solution".
DDurk.1
Associate II

The project was created with the language of C++ in CubeIDE.

Here is the complete dump of the errors that occur during the build. Only the first two are interesting. I have corrected the warnings.

Description Resource Path Location Type

fatal error: string: No such file or directory main.cpp /Slave-SPI/Application/User/Core line 31 C/C++ Problem

make: *** [Application/User/Core/subdir.mk:55: Application/User/Core/main.o] Error 1 Slave-SPI C/C++ Problem

comparison of integer expressions of different signedness: 'int' and 'unsigned int' [-Wsign-compare] main.cpp /STM32-SPI-Slave/Core/Src line 209 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 161 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 202 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 226 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 232 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 238 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 244 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 250 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 256 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 273 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 339 C/C++ Problem

ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] main.cpp /STM32-SPI-Slave/Core/Src line 350 C/C++ Problem

Thank you sir! That did the trick. Why do I need the .h? When I write C++ outside this environment and compile it with g++ I don't need the .h on the includes.

Question: Why does #include <string> require me to add the .h but #include <cstdio> chokes if I add the .h?