I am getting fatal errors stating that the header file is not recognized
You need to install the package which provides that header file (and much more) first.
Ubuntu:
sudo apt install linux-libc-dev
Fedora:
sudo dnf install glibc-headers
If you use any other OS, you need to find the correct package using the tools provided with the OS
Then, if you have everything else in place, this should compile and display the information:
#include <sys/utsname.h>
#include <iostream>
// a small helper to display the content of an utsname struct:
std::ostream& operator<<(std::ostream& os, const utsname& u) {
return os << "sysname : " << u.sysname << '\n'
<< "nodename: " << u.nodename << '\n'
<< "release : " << u.release << '\n'
<< "version : " << u.version << '\n'
<< "machine : " << u.machine << '\n';
}
int main() {
utsname result; // declare the variable to hold the result
uname(&result); // call the uname() function to fill the struct
std::cout << result; // show the result using the helper function
}
Example output from my Ubuntu 20.04 (WSL2):
sysname : Linux
nodename: TED-W10
release : 4.19.104-microsoft-standard
version : #1 SMP Wed Feb 19 06:37:35 UTC 2020
machine : x86_64