【发布时间】:2021-05-15 12:57:33
【问题描述】:
我正在编写一个程序,它使用
我目前在 VS、CLion 和 csegrid 上运行。
【问题讨论】:
标签: c++ linux-kernel uname
我正在编写一个程序,它使用
我目前在 VS、CLion 和 csegrid 上运行。
【问题讨论】:
标签: c++ linux-kernel uname
我收到致命错误,指出无法识别头文件
您需要先安装提供该头文件(以及更多)的软件包。
Ubuntu:
sudo apt install linux-libc-dev
Fedora:
sudo dnf install glibc-headers
如果您使用任何其他操作系统,则需要使用操作系统提供的工具找到正确的软件包
然后,如果你有其他一切,这应该编译并显示信息:
#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
}
我的 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
【讨论】: