相关文章推荐
眼睛小的野马  ·  Common application ...·  3 天前    · 
逃课的消炎药  ·  Typescript build with ...·  1 年前    · 
刚分手的椰子  ·  Clipboard.SetText ...·  1 年前    · 
勤奋的香槟  ·  Android Activity ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Disclaimer - I am completely new to C++ and the way this language works regarding compiling / linking. Using MacOS Mojave.

For a school course we are obliged to use the g++ compiler to compile our c++ projects. G++ seems to be successfully installed; g++ -v results in the following output:

COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin17.5.0/8.1.0/lto-wrapper
Target: x86_64-apple-darwin17.5.0
Configured with: ../gcc-8.1.0/configure --enable-languages=c++,fortran
Thread model: posix
gcc versie 8.1.0 (GCC) 

I created my first "hello world" program:

#include <iostream>
using namespace std;
int main() {
    cout << "Hello, World!" << endl;
    return 0;

When I tried to compile this code (using 'g++ file.cpp), the following terminal output prompted:

In file included from /usr/local/include/c++/8.1.0/bits/postypes.h:40,
                 from /usr/local/include/c++/8.1.0/iosfwd:40,
                 from /usr/local/include/c++/8.1.0/ios:38,
                 from /usr/local/include/c++/8.1.0/ostream:38,
                 from /usr/local/include/c++/8.1.0/iostream:39,
                 from ex1.cpp:1:
/usr/local/include/c++/8.1.0/cwchar:44:10: fatale fout: wchar.h: No such file or directory
 #include <wchar.h>
          ^~~~~~~~~
compilation ended.

The whcar.h file is indeed not present in the above folder. After some digging, I found the whcar file in the following folder: /Library/Developer/CommandLineTools/usr/include/c++/v1

Unfortunately I am a bit lost and don't really know what I am talking about, consindering everything is really new for me.

It is greatly appreciated if anyone can guide me in the right direction.

Kind regards,

Thijmen.

can you paste exact command yup are exacting to perform a compilation? For example something like this should do the trick: g++ prog.cpp -Wall -std=c++17 -o prog – Marek R Sep 12, 2018 at 12:50 I used only 'g++ prog.cpp'. Using your command results in the same error as stated in my original post. – Thijmen Sep 12, 2018 at 12:51 So looks like installation was not completed successfully. It should work out of the box. Offtopic: you are using Mac so why you do not use clang? – Marek R Sep 12, 2018 at 12:52 Do I have to perform any actions before trying to install g++ again? Also, do you have a good source of how to install g++ correctly on Mac? Sorry, I really am new to all of this. – Thijmen Sep 12, 2018 at 12:53

For me, reinstalling Xcode Command Line Tools and g++ solved the same issue:

xcode-select --install
brew reinstall gcc

The last line is assuming you have installed homebrew.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.