Search code examples
c++stringincludevisualmicro

fatal error: string: No such file or directory #include <string>


NB, C++ beginner here, but I have reasonable experience coding in other languages (and significantly less sophisticated development environments).

I am working in visual studio using visual micro to work on an arduino project. The details of the project are not important, as, at this point, I am encountering the error in a completely empty .ino/.cpp file:

fatal error: string: No such file or directory #include <string>
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ^~~~~~~~ compilation terminated

An error was encountered during the 'Deep Search' library discovery process. Build failed for project 'CylinderPrinter'

#include <string>

// the setup function runs once when you press reset or power the board
void setup() {
    string h = "";
}

// the loop function runs over and over again until power down or reset
void loop() {
  
}

I have tried a number of things so far, as this seems to be a somewhat common error:

  1. Most permutations of: #include "string"; #include "string.h"; #include ; #include ; #include <string.h>; using namespace std (which is apparently bad practice); etc.
  2. Including both the "string" and "string.h" dependencies within my project, rather than referencing them as external dependencies (in this case, the compiler marks 'string is undefined in this scope')
  3. Calling string as std::string to avoid namespace issues (compiler states 'string is not a member of std')
  4. Altering the target paths in the compiler window (admittedly I have no idea what I am doing here, so I could probably use some advice...)
  5. Reinstalling the Visual C++ redistributable (I have tried x86 and x64...)
  6. Restarting my code in a new project
  7. Restarting my code in the arduino development environment (same error, which I imagine suggests a systemic problem).

As far as I can tell, I have made no meaningful progress. Here are some additional screenshots that could possibly be helpful:

Please let me know if there's additional information that could prove helpful.

... . . . ...


Solution

  • so, the standard library is provided by the compiler. For the most popular ones, like gcc, clang, or msvc, the provided library is 99% standard compliant. But some micro controller compilers might not have STL support. Check the Arduino STL support for your compiler. And as far as I know, there's an official Arduino IDE, try using that