我正在Ubuntu 18上用C ++构建一个简单的计时器,该计时器运行数毫秒,并在完成后调用回调。但是,当我尝试启动新线程时,从编译器中收到一个奇怪的错误,指出:
prefetchnta
我正在使用CLion,我上线并尝试寻找解决方案,但到目前为止,我什么都没找到。 这是我在新线程中启动计时器的方法:
CMakeFiles/SourceCode.dir/main.cpp.o: In function `std::thread::thread<void (Timer::*)(), Timer*&>(void (Timer::*&&)(), Timer*&)':
/usr/include/c++/7/thread:122: undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
CMakeFiles/SourceCode.dir/build.make:128: recipe for target 'SourceCode' failed
make[3]: *** [SourceCode] Error 1
CMakeFiles/Makefile2:72: recipe for target 'CMakeFiles/SourceCode.dir/all' failed
make[2]: *** [CMakeFiles/SourceCode.dir/all] Error 2
CMakeFiles/Makefile2:84: recipe for target 'CMakeFiles/SourceCode.dir/rule' failed
make[1]: *** [CMakeFiles/SourceCode.dir/rule] Error 2
Makefile:118: recipe for target 'SourceCode' failed
make: *** [SourceCode] Error 2
这是我运行计时器的方式:
void Timer::startTimer() {
std::thread t1(&Timer::checkTimer, this);
}
请有人帮我吗?我是C ++的新手,我很难找出问题的原因。