Error in sysconf() in C++

Error in sysconf() in C++

本文关键字:in C++ sysconf Error      更新时间:2023-10-16

我正在编译一个程序,它给了我以下错误。gcc的版本是(gcc) 4.8.5 20150623 (Red Hat 4.8.5-4.

Utils.cpp: In static member function ‘static double Utils::process_mem_usage()’:
Utils.cpp:33:30: error: ‘_SC_PAGE_SIZE’ was not declared in this scope
  long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // if x86-64 is configured to use 2MB pages
                              ^
Utils.cpp:33:43: error: ‘sysconf’ was not declared in this scope
  long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // if x86-64 is configured to use 2MB pages

包含<unistd.h>,其中定义_SC_PAGE_SIZE,声明sysconf()

参见POSIX规范:http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/unistd.h.html