【发布时间】:2022-01-27 20:56:19
【问题描述】:
当我尝试构建 Google 测试 c++ 项目时,我发现了错误
Error C3861 't1': identifier not found
Error C2065 't1': undeclared identifier
Error C2039 'thread': is not a member of 'std'
Error C2065 'thread': undeclared identifier
Error C2146 syntax error: missing ';' before identifier 't1'
我的测试代码是:
#include <future>
#include <thread>
#include "pch.h"
TEST(...)
{
// preconditions here
std::thread t1([&] {
Sleep(100);
testee.enqueue(item);
});
t1.join();
// other logic
}
为什么我不能在我的项目中使用 std::thread 和其他 C++11 功能?我该怎么做?
【问题讨论】:
-
你
#include <thread>了吗?哪个版本的视觉工作室?哪些编译器标志? -
@mch 是的,我做了
#include <thread>。我使用 Visual Studio 2017。在哪里可以看到 VS 2017 中的编译器标志? -
@AlanBirtles,希望我按照你的意愿编辑
-
Visual Studio 2017 支持 C++14(默认)或 C++17 标准。它不支持旧标准,所以
<thread>肯定是众所周知的。正如@273K 回答的那样,问题是由预编译的标头引起的。
标签: c++ visual-studio c++11 googletest