How to find out the number of cores or processors available in C

Hi,
I got a following program to return the number of cores:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <stdio.h>
#include <libcpuid.h>

int main(void)
{
    struct cpu_raw_data_t raw;
    struct cpu_id_t data;

    cpuid_get_raw_data(&raw);
    cpu_identify(&raw, &data);
    printf("No. of Physical Core(s) : %d\n", data.num_cores);
    return 0;
}

I am getting error on #include <libcpuid.h>. I am working on ubuntu 18.04.
Can somebody please guide me how to find the number of cores?

Zulfi.
Why don't you tell us what the error is? We can't control your computer.

I see directions for installation here: https://github.com/anrieff/libcpuid (scroll down to the Readme).

For the compiler commands of the test program, see: http://libcpuid.sourceforge.net/documentation.html
If your error is that it can't find the .h file,
The development headers must be placed in your search path. Under UNIX-like OSes with pkg-config, this is achieved with "pkg-config libcpuid --cflags".


I don't currently have the ability to install it myself, but try to understand both of those pages.
Topic archived. No new replies allowed.