找到此代码,需要停止将戴尔笔记本电脑中的 CPU 节流至 20%,这是由于电源适配器无法被计算机识别而发生的。
\n\n尝试在 Kubuntu 上编译并得到以下结果:
\n\nwarning: implicit declaration of function \xe2\x80\x98asprintf\xe2\x80\x99; did you mean \xe2\x80\x98vasprintf\xe2\x80\x99? [-Wimplicit-function-declaration]\n 47 | if (asprintf(&concat_cmd, "%s %i", cmd, *reg_value) == -1)\n | ^~~~~~~~\n | vasprintf\nRun Code Online (Sandbox Code Playgroud)\n\n我不明白为什么会发生这种情况。我读到这是libiberty-devasprintf的一部分。库已安装,但一切都不起作用。我还添加了
#include <libiberty/libiberty.h>\nRun Code Online (Sandbox Code Playgroud)\n\n并得到相同的 - 函数 \xe2\x80\x98asprintf\xe2\x80\x99 的隐式声明
\n\n告诉我该怎么办?
\n\n#include <string.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <stdint.h>\n#include <libiberty/libiberty.h>\n\n#define BUFSIZE (64)\n\nint get_msr_value(uint64_t *reg_value) {\n const char *cmd = "rdmsr -u 0x1FC";\n char cmd_buf[BUFSIZE];\n\n FILE *fp;\n\n if ((fp = popen(cmd, "r")) == NULL) {\n printf("Error opening pipe!\\n");\n return -1;\n }\n\n cmd_buf[strcspn(fgets(cmd_buf, BUFSIZE, fp), "\\n")] = 0;\n *reg_value = atoi(cmd_buf);\n\n if (pclose(fp)) {\n printf("Command not found or exited with error status\\n");\n return -1;\n }\n\n return 0;\n}\n\nint main(void) {\n const char *cmd = "wrmsr -a 0x1FC";\n char *concat_cmd;\n int ret;\n uint64_t *reg_value = &(uint64_t){ 0 };\n\n if ((ret = get_msr_value(reg_value))) {\n return ret;\n }\n\n printf("Old register value: %lu\\n", *reg_value);\n\n *reg_value = *reg_value & 0xFFFFFFFE; // clear bit 0\n\n printf("New register value: %lu\\n", *reg_value);\n\n if (asprintf(&concat_cmd, "%s %i", cmd, *reg_value) == -1)\n return -1;\n\n printf("Executing: %s\\n", concat_cmd);\n\n system(concat_cmd);\n free(concat_cmd);\n\n return 0;\n}\nRun Code Online (Sandbox Code Playgroud)\n