Error: 'get_nprocs was not declared in this scope

I am using this code to work 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, what header files should I include?

+1


source to share


1 answer


We have to include the appropriate header file



#include <sys/sysinfo.h>

      

+2


source







All Articles