error: ‘get_nprocs’ was not declared in this scope
error: ‘get_nprocs’ was not declared in this scope
我正在使用这段代码来处理旧的 g++ 编译器。我从 this 回答中得到这个。
unsigned thread::hardware_concurrency()
{
#if defined(PTW32_VERSION) || defined(__hpux)
return pthread_num_processors_np();
#elif defined(__APPLE__) || defined(__FreeBSD__)
int count;
size_t size=sizeof(count);
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
int const count=sysconf(_SC_NPROCESSORS_ONLN);
return (count>0)?count:0;
#elif defined(_GNU_SOURCE)
return get_nprocs();
#else
return 0;
#endif
}
这里是错误:
Hardware_con.h:31:25: error: ‘get_nprocs’ was not declared in this scope
return get_nprocs();
^
所以问题是我应该包含哪些头文件?
我们应该包含相应的头文件
#include <sys/sysinfo.h>
我正在使用这段代码来处理旧的 g++ 编译器。我从 this 回答中得到这个。
unsigned thread::hardware_concurrency()
{
#if defined(PTW32_VERSION) || defined(__hpux)
return pthread_num_processors_np();
#elif defined(__APPLE__) || defined(__FreeBSD__)
int count;
size_t size=sizeof(count);
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
#elif defined(BOOST_HAS_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
int const count=sysconf(_SC_NPROCESSORS_ONLN);
return (count>0)?count:0;
#elif defined(_GNU_SOURCE)
return get_nprocs();
#else
return 0;
#endif
}
这里是错误:
Hardware_con.h:31:25: error: ‘get_nprocs’ was not declared in this scope
return get_nprocs();
^
所以问题是我应该包含哪些头文件?
我们应该包含相应的头文件
#include <sys/sysinfo.h>