Lin Weiye
Lin Weiye

Reputation: 185

/usr/bin/locale: source file is not valid UTF-8

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 I run:

g++ hello.cpp

error

Upvotes: 4

Views: 1280

Answers (2)

KOJI K
KOJI K

Reputation: 1

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.

Upvotes: 0

Lin Weiye
Lin Weiye

Reputation: 185

CPLUS_INCLUDE_PATH environment variable has an incorrect value.

Simple fix:

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

Upvotes: 2

Related Questions