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
CPLUS_INCLUDE_PATH
environment variable has an incorrect value.
Simple fix:
export CPLUS_INCLUDE_PATH=":/usr/local/include"
Similar problem happened 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.
file hello.cpp
... what does it say?locale
executable on your system and treating it as the<locale>
header that<iostream>
uses. Why? No idea.CPATH
andCPLUS_INCLUDE_PATH
environment variables? (echo $CPATH
etc.) Do they include/usr/bin
?