我正在嘗試使用mman.h我的 c 代碼中的函式。代碼使用 g /clang 編譯得很好,但是當使用 gcc/clang 時它說memfd_create沒有被宣告,但是代碼仍然運行良好。
我嘗試使用godbolt在線編譯,它與本地相同,所以我懷疑我的設定有問題。有誰知道為什么會這樣?我正在使用 gcc 11.3 和 clang 14。
#include <stdint.h>
#include <stdio.h>
#define _GNU_SOURCE
#include <sys/mman.h>
int main()
{
int32_t fd = memfd_create("", 0);
if (fd == -1)
{
printf("Error creating fd\n");
return -1;
}
return 0;
}
編譯警告:
main.c:9:15: warning: implicit declaration of function 'memfd_create' is invalid in C99 [-Wimplicit-function-declaration]
int32_t fd = memfd_create("", 0);
uj5u.com熱心網友回復:
_GNU_SOURCE必須在 any 之前#include。見man feature_test_macros。
#define _GNU_SOURCE
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/523661.html
標籤:Clinux海合会铛
上一篇:如何避免在單鏈表中的給定節點之后插入新節點時獲得垃圾值?
下一篇:學習C基礎知識并需要一些幫助:
