error: ‘get_nprocs’ was not declared in this scope

旧街凉风 提交于 2019-12-11 13:36:16

问题


I am using this code for dealing with old g++ compilers. I got this from this answer.

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
}

Here is the error:

Hardware_con.h:31:25: error: ‘get_nprocs’ was not declared in this scope
       return get_nprocs();
                         ^

So the question is which header files I should include?


回答1:


We should include the corresponding header file

#include <sys/sysinfo.h>


来源:https://stackoverflow.com/questions/27981038/error-get-nprocs-was-not-declared-in-this-scope

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!