0

I am new to mingw/C++ and would like to compile and run the following code I found online:

#include <iostream>
using namespace std;

int main() 
{
    cout << "Hello, World!";
    return 0;
}

Unfortunately, running a g++ helloworld.cpp -o helloworld.exe throws the following error:

In file included from c:\mingw\include\_mingw.h:73,
                 from c:\mingw\include\wchar.h:53,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\cwchar:44,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\bits\postypes.h:40,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iosfwd:40,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ios:38,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\ostream:38,
                 from c:\mingw\lib\gcc\mingw32\8.2.0\include\c++\iostream:39,
                 from helloworld.cpp:1:
c:\mingw\include\w32api.h:59:10: fatal error: sdkddkver.h: No such file or directory
 #include <sdkddkver.h>
          ^~~~~~~~~~~~~
compilation terminated.

I have the impression this is related to Windows SDK and triggered by #include <iostream>. What is <iostream>, why is it important here and how can I get it to compile with g++?

EDIT g++ version information

D:\TEMP\mingw_example>g++ --version
g++ (MinGW.org GCC-8.2.0-5) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
user32882
  • 5,094
  • 5
  • 43
  • 82
  • Your compiler is somehow broken. Uninstall it and get a new one. (A good way of getting MinGW on Windows is from MSYS2.) – HolyBlackCat Feb 25 '20 at 17:12
  • I'm using MinGW installation manager and installing the individual components separately. Is it absolutely necessary to get MSYS2 or reinstall everything? I had no errors in the initial install.... I'd rather figure out what the problem is ... – user32882 Feb 25 '20 at 17:16
  • are you using minggw64? – vsh Feb 25 '20 at 17:19
  • Not sure... How do I determine that? – user32882 Feb 25 '20 at 17:20
  • @user32882 No, you can also try uninstalling MinGW and reinstalling it the same way you did before. I personally prefer MSYS2 because it has a newer GCC (9.2 instead of 8.2 that you got). – HolyBlackCat Feb 25 '20 at 17:21
  • @user32882 *"How do I determine that?"* Where did you download mingw? – HolyBlackCat Feb 25 '20 at 17:21
  • I don't quite remember, probably from source forge.... is there a command line option which I can run to provide this information? Please see edit to original question – user32882 Feb 25 '20 at 17:23
  • @user32882 Regarding the edit: So it's not MinGW-w64, but the original MinGW. Even if you made MinGW work, it would still be worth it to switch to MinGW-w64 (see https://en.wikipedia.org/wiki/Mingw-w64 for why it's better). I suggest either getting [the official build of MinGW-w64](https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download) or installing it from [MSYS2](https://www.msys2.org/). – HolyBlackCat Feb 25 '20 at 17:27
  • [Good instructions for installing GCC via MSYS2](https://stackoverflow.com/a/30071634/4581301) – user4581301 Feb 25 '20 at 17:33
  • how do I remove the version already installed on my system? – user32882 Feb 25 '20 at 19:35
  • @HolyBlackCat If you want to formulate your comments as an answer I'd be glad to accept it as they have helped me solve the problem. – user32882 Feb 26 '20 at 05:11

0 Answers0