C ++未解决的标识符将来

时间:2018-09-08 22:17:25

标签: c++

我正在学习如何在c ++中使用多线程,因此遇到了这个问题。我搜索了互联网,但没有找到满意的答案。 我很确定图书馆的目录也包括在内。

这是我的系统规格:

Oracle Virtual box 5.2.12 
Debian 9 
Netbeans 8.2 
gcc and g++ 6.3.0 

这是错误

Cannot find include file "/usr/include/c++/6".
unable to resolve identifier future.
unable to resolve identifier get.

这是我的教程代码:

// async example
#include <iostream>       // std::cout
#include <future>         // std::async, std::future

// a non-optimized way of checking for prime numbers:
bool is_prime (int x) {
  std::cout << "Calculating. Please, wait...\n";
  for (int i=2; i<x; ++i) if (x%i==0) return false;
  return true;
}

int main ()
{
  // call is_prime(313222313) asynchronously:
  std::future<bool> fut = std::async (is_prime,313222313);

  std::cout << "Checking whether 313222313 is prime.\n";
  // ...

  bool ret = fut.get();      // waits for is_prime to return

  if (ret) std::cout << "It is prime!\n";
  else std::cout << "It is not prime.\n";

  return 0;
}

这是建筑物的输出:

cd '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
/usr/bin/make -f Makefile CONF=Debug
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: se entra en el directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
"/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux/asynctutorial
make[2]: se entra en el directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
mkdir -p build/Debug/GNU-Linux
rm -f "build/Debug/GNU-Linux/main.o.d"
g++    -c -g -include /usr/include/c++/6.3.0 -MMD -MP -MF "build/Debug/GNU-Linux/main.o.d" -o build/Debug/GNU-Linux/main.o main.cpp
cc1plus: fatal error: /usr/include/c++/6.3.0: No existe el fichero o el directorio
compilation terminated.
nbproject/Makefile-Debug.mk:66: fallo en las instrucciones para el objetivo 'build/Debug/GNU-Linux/main.o'
make[2]: *** [build/Debug/GNU-Linux/main.o] Error 1
make[2]: se sale del directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
nbproject/Makefile-Debug.mk:59: fallo en las instrucciones para el objetivo '.build-conf'
make[1]: *** [.build-conf] Error 2
make[1]: se sale del directorio '/home/sulheru/NetBeansProjects/20180907/asyncTutorial'
nbproject/Makefile-impl.mk:39: fallo en las instrucciones para el objetivo '.build-impl'
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 323ms)

1 个答案:

答案 0 :(得分:2)

您需要在编译器标志中使用-pthread选项。

示例:

➜ g++ -std=c++11 -pthread async.cpp

➜ ./a.out                            
Checking whether 313222313 is prime.
Calculating. Please, wait...
It is prime!