I would like to use the libcpuid library and provide it as a bundle to my main application written in Python (I'm planning to wrap the C library using ctypes
).
I am trying to run the example program available in the official documentation but I am always getting the error:
main.c:2:10: fatal error: libcpuid.h: No such file or directory
#include <libcpuid.h>
^~~~~~~~~~~~
What I did was following the instruction from the Readme.md of the project:
git clone https://github.com/anrieff/libcpuid.git
cd libcpuid/
libtoolize
autoreconf --install
./configure
make
The compilation went through without errors and I noticed that I had a new hidden folder libcpuid/.libs/
containing the following files:
asm-bits.o
cpuid_main.o
libcpuid.a
libcpuid.la -> ../libcpuid.la
libcpuid.lai
libcpuid.so -> libcpuid.so.14.0.0*
libcpuid.so.14 -> libcpuid.so.14.0.0*
libcpuid.so.14.0.0*
libcpuid_util.o
libcpuid.ver
msrdriver.o
rdmsr.o
rdtsc.o
recog_amd.o
recog_intel.o
I know that adding this library to the system shared libraries will probably fix all my issues, but I am trying to see if I can deploy this library together with my app so that I can control the version that is used.
I have created a new main.c
file outside the project directory containing the sample code:
#include <stdio.h>
#include <libcpuid.h>
int main(void)
{
if (!cpuid_present()) { // check for CPUID presence
printf("Sorry, your CPU doesn't support CPUID!\n");
return -1;
}
struct cpu_raw_data_t raw; // contains only raw data
struct cpu_id_t data; // contains recognized CPU features data
if (cpuid_get_raw_data(&raw) < 0) { // obtain the raw CPUID data
printf("Sorry, cannot get the CPUID raw data.\n");
printf("Error: %s\n", cpuid_error()); // cpuid_error() gives the last error description
return -2;
}
if (cpu_identify(&raw, &data) < 0) { // identify the CPU, using the given raw data.
printf("Sorrry, CPU identification failed.\n");
printf("Error: %s\n", cpuid_error());
return -3;
}
printf("Found: %s CPU\n", data.vendor_str); // print out the vendor string (e.g. `GenuineIntel')
printf("Processor model is `%s'\n", data.cpu_codename); // print out the CPU code name (e.g. `Pentium 4 (Northwood)')
printf("The full brand string is `%s'\n", data.brand_str); // print out the CPU brand string
printf("The processor has %dK L1 cache and %dK L2 cache\n",
data.l1_data_cache, data.l2_cache); // print out cache size information
printf("The processor has %d cores and %d logical processors\n",
data.num_cores, data.num_logical_cpus); // print out CPU cores information
printf("Supported multimedia instruction sets:\n");
printf(" MMX : %s\n", data.flags[CPU_FEATURE_MMX] ? "present" : "absent");
printf(" MMX-extended: %s\n", data.flags[CPU_FEATURE_MMXEXT] ? "present" : "absent");
printf(" SSE : %s\n", data.flags[CPU_FEATURE_SSE] ? "present" : "absent");
printf(" SSE2 : %s\n", data.flags[CPU_FEATURE_SSE2] ? "present" : "absent");
printf(" 3DNow! : %s\n", data.flags[CPU_FEATURE_3DNOW] ? "present" : "absent");
printf("CPU clock is: %d MHz (according to your OS)\n",
cpu_clock_by_os()); // print out the CPU clock, according to the OS
printf("CPU clock is: %d MHz (tested)\n", cpu_clock_measure(200, 0)); // print out the CPU clock, measured with RDTSC.
return 0;
}
Then I tried to follow several instructions that I found online on how to build a C program using a shared library:
gcc -l/home/user/temp/libcpuid/libcpuid/.libs/libcpuid.so main.c
gcc -Wall -o test main.c -lcpuid
gcc -L/home/user/temp/libcpuid/libcpuid/.libs/ -Wall -o test main.c -lcpuid
export LD_LIBRARY_PATH=/home/user/temp/libcpuid/libcpuid/.libs/
gcc -o main main.c -lcpuid -L/home/user/temp/libcpuid/libcpuid/.libs/
but with every command I only and always got the same error:
main.c:2:10: fatal error: libcpuid.h: No such file or directory
#include <libcpuid.h>
^~~~~~~~~~~~
I tried also to use double quotes instead of angular brackets for the libcpuid.h
but there was no difference.
I am sure I am doing something silly since I have a very limited experience with C (perhaps the make
command is not building a shared library? How can I check?)
What I have to do to run my sample app without having to add this library to the system shared libraries?