0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

error: no member named 'signbit' in the global namespaceと/usr/bin/locale:1:1: error: source file is not valid UTF-8のお話

Last updated at Posted at 2020-10-07

これは私が解決した解決策です。
osはmacOS Catalina バージョン10.15.7

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

c++で.cppファイルをコンパイルしようとg++ hello.cpp としたときに下記のようにエラーがでた。

hello.cpp
# include <iostream>
using namesapce std;
int main() { cout << "hello" << endl; }
エラー内容(抜粋)
/usr/bin/locale:1:1: error: source file is not valid UTF-8
<CF><FA><ED><FE><U+0007><U+0000><U+0000><U+0001><U+0003><U+0000><U+0000><U+0000><U+0002><U+0000><U+0000><U+0000><U+0012><U+0000><U+0000><U+0000>x<U+0007><U+0000><U+0000><85><80>!<U+0000>...
(以下同様のエラーが多数なので省略)
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.

これは、iostream内でlocaleというファイルを呼び出すようなのですが、usr/bin/にあるlocaleと競合してしまったようです。
このように競合してしまったのは、私が.zshrc(bashだと.bash_profile)にCPATHを通そうと以下のようにexport CPATH="$PATH:/usr/....(以下省略)と書いてしまったからです。$PATHとなっていて、CPATHに $PATH が全部乗ってしまっていました。そのため、/usr/binのなかにあるlocaleを見てutf-8じゃないと言われたわけです。つまり、 " " の中に $CPATH ではなく、$PATHと書いてあったら$CPATHと書き直しましょう。
こんな間違い他にする人がいないかもしれませんが、このエラーで困っているひとはパスが間違えてないかみてみると幸せになるかもしれません.

 エラー再現方法

g++ ファイル名 -I /usr/bin で同様のエラーが出ますね。()

error: no member named 'signbit' in the global namespace

c++のcmathを使ったプログラムをコンパイルした時に下のようなエラーが出ました。

/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:318:9: error: 
      no member named 'signbit' in the global namespace
using ::signbit;
(同様のエラーが多数)

これと同様のエラーが出ている人もいましたが、いまいち原因が分からなかったのですが、homebrewでインストールしたg++でコンパイルしたら上手くコンパイル出来るようになりました。
原因としてXcodeを削除して再インストールしたので、ライブラリのパスがおかしくなったのかもしれません..

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?