I got a fatal error that the file or directory <stdlib> is not found on ubuntu 11.xx when I typed #include <stdlib>.
Is <stdlib> deprecated/removed, or is there something wrong with my GCC installation?
In C++ code, include 'cstdlib' instead.
#include <cstdlib>
If you are using C, include 'stdlib.h'
#include <stdlib.h>
In c++ code, always prefer the cXXX include instead of XXX.h
Presumably you are attempting to include the C standard library header stdlib.h.
Thing is, in C++, the old C headers x.h are deprecated; you should not use them. Fortunately, C++ allows you to use C++ versions of them:
#include <cstdlib>
It's pretty much the same thing, but wrapped into the std:: namespace ... and not deprecated.
Anyway, you got your error because there's certainly no standard header named just stdlib.
Related
I'm using mongoose to build an HTTP server in C++, and I'm getting an error message when I try to include other files in my program:
/Library/Developer/CommandLineTools/usr/include/c++/v1/cstdint:183:8: error:
expected unqualified-id
using::intptr_t;
^
/Users/cs/Downloads/mongoose-master/mongoose.c:2415:18: note:
expanded from
macro 'intptr_t'
#define intptr_t long
^
This happens whenever I attempt include the following files in my program:
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <iterator>
#include <sstream>
I've tried to narrow it down to one of these files causing the problem by commenting out some of them, but it appears that any one of them causes the error. Interestingly enough, string.h does not cause the error.
It sounds like your source code contains something like this:
#include <mongoose.c>
The .c file defines a macro that collides with words used in the standard library headers.
Including a .c file is not a good practice. Instead, you should build the mongoose library, and link your program against it.
If you really have to keep everything in a single translation unit, you should be able to move that dubious include statement to after all other headers, or even to the bottom of your cpp file.
But it would be best to figure out how to build mongoose.c separately, then link against the resulting library. You can ask a separate question, or see if you get anything out of this: Can't figure out how to build C application after adding Mongoose Embedded
I'm including a library in a C++ program, which includes memory and other libraries from the std c++ implementation, like so:
#include <memory>
There is an error happening:
Lexical or Preprocessor issue 'memory' file not found
This happens the same with all the includes in this file:
#include <cmath>
#include <vector>
I'm wondering what could cause such an issue? Could it be that the compiler is not set somewhere properly in the build settings? If so, any idea where?
I am trying to build my code using the Intel C++ Compiler, but for some reason it fails with this error:
catastrophic error: cannot open source file "stdio.h"
In this line #include <stdio.h>.
Any ideas?
stdio.h is a standard header file; it's a bad idea to have a local file of the same name. If you meant to include the standard header, it should be on your include path, and you should include it with
#include <stdio.h>
You should also consider whether you might get more benefit from including <iostream> or including <cstdio> (like including <stdio.h>, but puts the symbols safely into the std namespace).
If you're running on Windows, then installing Visual Studio, then invoking "psxevars.bat" might solve your problem, it solved it for me.
I know that clang can compile C++ files as .mm, but CImg comes as just an individual .h file. Regardless if I change the extension to .mm or keep it as .h, it doesn't work.
First, it complains that it can't find cstdio.h. As a result, I changed all the cstd.. imports to their c counterpart as a
// Include standard C++ headers.
// This is the minimal set of required headers to make CImg-based codes compile.
#include <stdio.h> // (was #import <cstdio>)
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <exception.h>
After bringing in the x11 library, I get past the import errors into syntax errors:
namespace cimg_library_suffixed {
Error: Unknown type name 'namespace'
Is this because I changed cstdio to stdio? I'm confused..
The solution in answer form for future reference:
Compile the file the header is #included from as Obj-C++ and the header will get treated as C++ code.
First things first: I'm a newbie in C/C++.
I have a library that I have to include but it has header files that use
#include <string>
I tried to include <string> but it failed. I can
#include <string.h>
though. Since it's a library I'm trying to use I can't do much about this import right ? How can I fix this problem ? Build terminates with a fatal error.
(In case that's important I'm working on Linux and genicam is the 3rd party library)
<string> is a standard C++ header. Either your compiler is broken, or installed incorrectly, or you are trying to use a C compiler on C++ code (for instance by using gcc instead of g++).