【发布时间】:2021-03-06 20:44:04
【问题描述】:
g++ -std=c++11 -Wall -g threads.cpp -o threads.out
In file included from threads.cpp:1:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iostream:37:
In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/ios:215:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:401:32: error: use of undeclared identifier '_ISspace'
static const mask space = _ISspace;
^
Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:402:32: error: use of undeclared identifier '_ISprint'
static const mask print = _ISprint;
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:403:32: error: use of undeclared identifier '_IScntrl'
static const mask cntrl = _IScntrl;
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:404:32: error: use of undeclared identifier '_ISupper'
static const mask upper = _ISupper;
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:405:32: error: use of undeclared identifier '_ISlower'
static const mask lower = _ISlower;
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__locale:406:32: error: use of undeclared identifier '_ISalpha'
static const mask alpha = _ISalpha;
您能否在编译 c++ 代码时帮我解决这个 __locale 问题。
#include <iostream>
#include <thread>
using namespace std;
void fun(void)
{
cout << "Vaule " << 10 << endl;
}
int main()
{
thread t1(fun);
thread t2(fun);
return 0;
}
编译命令: g++ -std=c++11 -Wall -g thread.cpp -o thread.out
【问题讨论】:
-
你试过用clang吗?
-
请显示
g++ --version的输出。 -
除非它是从 hombrew(或其他包管理器)安装的,否则 macOS 上的 g++ 是 clang++ 的别名,它也使用较旧的标准库。我没有消息来源可以证实这一点,但考虑到它有时的行为方式,以及当你查看
g++ --version时它吐出的信息,这对我来说似乎是一个合理的结论。试试 clang++ 看看是否还会出现。我不记得你是否需要在 macOS 上使用-pthread作为编译选项,但检查起来很快。 -
@G.M. ` sekharpa : g++ --version Apple clang 版本 12.0.0 (clang-1200.0.32.29) 目标:x86_64-apple-darwin20.3.0 线程模型:POSIX InstalledDir: /Library/Developer/CommandLineTools/usr/bin`
-
@sweenish 我也试过用 clang 和 clang++ 编译,还是一样的问题。使用 -lptherad 编译后也会出现相同的错误。