[Solved] error: ‘getrusage’ was not declared in this scope


Error:

vb_perf.cpp: In function ‘int main(int, const char**)’:
vb_perf.cpp:63:23: error: variable ‘main(int, const char**)::rusage rusage’ has initializer but incomplete type
   63 |         struct rusage rusage = { };
      |                       ^~~~~~
vb_perf.cpp:64:19: error: ‘RUSAGE_SELF’ was not declared in this scope
   64 |         getrusage(RUSAGE_SELF, &rusage);
      |                   ^~~~~~~~~~~
vb_perf.cpp:64:9: error: ‘getrusage’ was not declared in this scope; did you mean ‘rusage’?
   64 |         getrusage(RUSAGE_SELF, &rusage);
      |         ^~~~~~~~~
      |         rusage


Solution:

Include this header to your source code:

#include <sys/resource.h>

This compile error means the program used getrusage and struct rusage without including the header that declares them, so the compiler sees an incomplete type and stops.

Including sys/resource.h, and sys/time.h where needed, brings in the declarations and resolves it. getrusage reports resource usage such as CPU time and memory for the calling process on Unix like systems.

Comments

Popular posts from this blog

[Solved] Error: No such keg: /usr/local/Cellar/gcc

[How To] Unfollow Non-followers on Instagram