I've been trying to run simple c++ program
#include<iostream.h>
void main(){
cout<<"helloworld";
}
and the error I get is :
In file included from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\bits\postypes.h:40:0,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\iosfwd:40,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\ios:38,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\ostream:38,
from d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\iostream:39,
from my.cpp:1:
d:\mingw\lib\gcc\mingw32\6.3.0\include\c++\cwchar:44:19: fatal error: wchar.h: No such file or directory
#include <wchar.h>
^
compilation terminated."
anyone know how to fix it ,I'm using the mingw to compile it.
Probably your MinGW is broken. Also, GCC 6.3.0 is very old.
Try a more recent MinGW or even better MinGW-w64.
A standalone build is available from http://winlibs.com/ with GCC 10.2.0 (both for Windows 32-bit and 64-bit).
In my environment, I couldn't include <cstring>.
My g++ version is 4.9.3 (Homebrew gcc49 4.9.3).
The error is:
- /usr/local/Cellar/gcc49/4.9.3/include/c++/4.9.3/cstring:42:20: fatal
error: string.h: No such file or directory
"#include string.h"
But, in another environment (g++ 4.8.4[Ubuntu 4.8.4-2ubuntu1~14.04.3]), I can include <cstring> and run.
What's the problem and how do I solve it?
[P.S.]
Maybe, I misunderstood about the problem.
I tried to run my previous code, but got an error like this:
/usr/local/Cellar/gcc49/4.9.3/include/c++/4.9.3/cassert:43:20: fatal error: assert.h: No such file or directory
#include <assert.h>
Then, I can't run my code.
It is a g++'s problem.
I checked this article, but this procedure is not working.
I already installed xcode-select (commmad line tool) and I uninstalled xcode-select and reinstalled xcode-select, but it's not working.
Building C++ not working in OSX 10.9
Reinstalling the heaaders fixed my issue:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
Whenever I try to compile this code it always ends up with this error:
In file included from /usr/include/wchar.h:6:0,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/cwchar:44,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/bits/postypes.h:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iosfwd:40,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ios:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.9.2/include/c++/iostream:39,
from test.cpp:1:
/usr/include/sys/reent.h:14:20: fatal error: stddef.h: No such file or directory
#include <stddef.h>
^
compilation terminated.
The code I was trying to compile is:
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World! :D";
return 0;
}
The error is because your gcc-core package and gcc-g++ are not of the same version. Either downgrade one of them to solve the problem or update both the libraries. Updating both the libraries is the recommended way.
I had this error on a fresh MinGW install, it had nothing to do with the installed packages mentioned in the current accepted answer by "Prasanth Karri". In my case the issue was caused by -nostdinc in my Makefile. I actually only needed that compiler flag when building for a different target platform (not when using MinGW) so I fixed the issue by removing that flag from MinGW builds.
When I was incorporating a software library written in C into an existing demo project(used a C++ mbed library) I encountered this problem. The demo project would compile just fine, but after I replaced the existing main file by my own, this error occurred.
At this point I hadn't yet thought about the fact that the mbed library that I needed was written in C++. My own main file was a .c file that #include the mbed header file. As a result I used my normal C source as if it was a C++ source. Therefore the compiler that was used to compile my main file was the C compiler.
This C compiler then encountered a #include of a module that actually does not exist (within its scope), as it's not a C++ compiler.
Only after I inspected the output of the build log I realised the various source C and C++ files were compiled by more that 1 compiler(the c++ compiler). The project used used compilers arm-none-eabi-c++ and arm-none-eabi-gcc (for embedded systems) as seen below.
Compile log:
Building file: ../anyfile.cpp
Invoking: MCU C++ Compiler
arm-none-eabi-c++ <A lot of arguments> "../anyfile.cpp"
Finished building: ../anyfile.cpp
Building file: ../main.c
Invoking: MCU C Compiler
arm-none-eabi-gcc <A lot of arguments> "../main.c"
In file included from <Project directory>\mbed/mbed.h:21:0,
from ../main.c:16:
<Project directory>\mbed/platform.h:25:19: fatal error: cstddef: No such file or directory
compilation terminated.
Of course in a C++ environment cstddef exists, but in a C environment cstddef doesn't exist, in stead it's just C's implementation of stddef.
In other words, cstddef does not exist in the C compiler.
I resolved this problem by renaming my main.c file to main.cpp and the rest of the code compiled smoothly too.
TLDR/Conclusion: When building a C++ project, avoid mixing C files with C++ files(sources and headers). If possible rename .c files to .cpp files to use the C++ compiler in stead of the C compiler where required.
In order to update it, follow below.
If you are on Windows, just run these on command prompt or powershell
Update the package list: mingw-get update
After updating the package list, run: mingw-get upgrade
Source: How to update GCC in MinGW on Windows?
This problem was solved for me as I installed codeblocks with mingw compiler then I copied the mingw folder from codeblocks to C drive and added
C\mingw\bin to the environment variables.
If you try to compile and see a message like, "fatal error: stddef.h: No such file or directory", the error is because your gcc-core and gcc-g++ packages are not of the same version. Rerun the Cygwin install and make sure that you select the highest numbered versions of gcc-core and gcc-g++.
After installing the C++ compiler with MinGW I encountered this problem as well. Apparently, you have to also install mingw32-base. Go to C:/MinGW/bin/mingw-get.exe (my path) and check it for installation at the Basic Setup tab.
I'm compiling my project with clang but I'm having an odd error:
[ 1%] Building CXX object CMakeFiles/tfs.dir/src/actions.cpp.o
In file included from /home/travis/build/dominique120/miniature-adventure/src/actions.cpp:20:
In file included from /home/travis/build/dominique120/miniature-adventure/src/otpch.h:27:
/home/travis/build/dominique120/miniature-adventure/src/definitions.h:39:10: fatal error:
'cmath' file not found
#include <cmath>
^
make: *** [all] Error 2
My actions.cpp line 20:
#include "otpch.h"
otpch.h line 27:
#include "definitions.h"
definitions.h line 31:
#include <cmath>
I made a few edits but I have no idea what is causing this error, edits here: https://github.com/dominique120/miniature-adventure/commits/master
PS: GCC just dumps a ton of errors:
https://travis-ci.org/dominique120/miniature-adventure/jobs/21905513
After googling for a problem I was having on macOS, I came to your post. I am sharing a solution, even though it applies only to Mac users.
Chances are you upgraded Xcode (or it was upgraded for you) and you continue to use an old compilation scheme.
Determine which of the following directories actually exists on your disk:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk/
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/
and make sure that among your compilation switches you have -I along with a directory that exists.
I had the same issue on Ubuntu 22.04 with libstdc++-11-dev installed.
After doing:
sudo apt install libstdc++-12-dev
...the error went away.
It seems to occur with libstdc++-11 only?
When trying to make GLEW with MSYS, I'm getting the following error:
In file included from src/glew.c:37:0:
include/GL/glxew.h:97:22: fatal error: X11/Xlib.h: No such file or directory
#include <X11/Xlib.h>
compilation terminated.
make: *** [tmp/mingw/default/shared/glew.o] Error 1
Why?
MSYS does not have X11. It's *M*inimal SYStem for a reason. You want Cygwin.
Or if you want to keep things Win32 native without Cygwin, take a look at Xming.