2
votes

using g++ to compile cpp file in macOS.

macOS v10.15.4

Apple clang version 11.0.3 (clang-1103.0.32.62)

hello.cpp

#include <iostream>
using namespace std;

int main()
{
  cout << "hello word" << endl;
  return 0;
}

in terminal

g++ hell.cpp

error

2
Type file hello.cpp ... what does it say?Eljay
Somehow your compiler is finding the locale executable on your system and treating it as the <locale> header that <iostream> uses. Why? No idea.chris
What are the values of your CPATH and CPLUS_INCLUDE_PATH environment variables? (echo $CPATH etc.) Do they include /usr/bin?chris
hello.cpp: C++ source text, ASCII text @EljayLin Weiye
yes no idea @chrisLin Weiye

2 Answers

1
votes

it is CPLUS_INCLUDE_PATH environment variables error.

Setting export CPLUS_INCLUDE_PATH=":/usr/local/include"

0
votes

Similar problem happend for me on Catalina10.15.7 + gcc10.2( homebrew), and CPLUS_INCLUDE_PATH method from Lin Weiye didn't work somehow.

Manually changing line 140 of ostream header from

include <locale>

to

include "locale"

did work. This will stop ostream from looking for locale executable via PATH, and force to look locale header in the same directory where ofstream header is.