当我尝试编译包含另一个 C 标头的 C 代码时,我收到此错误:
x86_64-uefi/../../libk/string.h:9:10: error: function declared 'ms_abi' here was
previously declared without calling convention
KABI int memcmp(const void *d1, const void *d2, uint64_t len);
^
x86_64-uefi/../../libk/string.h:9:10: note: previous declaration is here
编译器是clang,涉及的文件如下:
memcmp.c
#include "../string.h"
KABI int memcmp(const void *d1, const void *d2, uint64_t len) {
const uint8_t *d1_ = d1, *d2_ = d2;
for(uint64_t i = 0; i < len; i += 1, d1_++, d2_++){
if(*d1_ != *d2_) return *d1_ < *d2_ ? -1 : 1;
}
return 0;
}
string.h
#pragma once
#include "systemapi.h"
#include "typedefs.h"
KABI int memcmp(const void *d1, const void *d2, uint64_t len);
systemapi.h
(typedefs 只是定义 uintx_t 类型)
#pragma once
#define KABI __attribute__((ms_abi))
另一个标题包括string.h
,libk.h
#pragma once
#include "string.h"
#include "systemapi.h"
#include "typedefs.h"
以及包含 lib.h 并且在编译时报告错误的文件,main.c
(但所有文件在链接时都报告错误lib.h
)
KABI void arch_main(void)
{
// The function does not uses memcmp, just uses the KABI part of lib.h
// Calling the whole lib.h is a convention
}
编译器的标志:-I/usr/include/efi -I/usr/include/efi/x86_64 -I/usr/include/efi/protocol -fno-stack-protector -fpic -fshort-wchar -mno-red-zone -DHAVE_USE_MS_ABI -c main.c -o main.o