0

My problem is I am getting an undefined reference error in linux g++

cpufreq.h is in usr/include directory and I included #include <cpufreq.h>. This has declaration for cpufreq_get_freq_kernel()

But when I call cpufreq_get_freq_kernel(), it gets a linker error:

undefined reference to `cpufreq_get_freq_kernel'

I am using netbeans to compile the program.

Any solution?

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • 3
    Please show us, how g++ and ld (linker) was called. Seems there is some problem with your libcpufreq library, e.g. it just not passed to g++ – osgx Dec 29 '12 at 05:30
  • Can you show your syntax for the call with the passed in value? It always returned zero for me. Had to fopen /sys/devices/../cpu0/cpufrequency/.. in order to get the value. – TheHairyOne May 10 '18 at 21:55

1 Answers1

2

Including headers is not usually enough, you also need to link to the library, which is probably done by adding -lcpufreq to your linker command.

Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521