[英]error: function declared 'ms_abi' here was previously declared without calling convention (clang)
when I try to compile C code that includes another C header I get this error:当我尝试编译包含另一个 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
The compiler is clang and the involved files are the following:编译器是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 just define the uintx_t types) systemapi.h
( systemapi.h
只是定义了 uintx_t 类型)
#pragma once
#define KABI __attribute__((ms_abi))
Another header that includes string.h
, libk.h
另一个包含
string.h
、 libk.h
头libk.h
#pragma once
#include "string.h"
#include "systemapi.h"
#include "typedefs.h"
And the file that includes lib.h and that reports the error when compiling, main.c
(but all files report the error when linking with lib.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
}
Flags of the compiler: -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
编译器的标志:
-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
Without having your build environment, an educated guess would be that you are redefining the built in functions that have prototypes that are incompatible with the ms_abi
function attribute.如果没有您的构建环境,有根据的猜测是您正在重新定义具有与
ms_abi
函数属性不兼容的原型的ms_abi
函数。 If you are compiling with -ffreestanding
and supplying your own functions like memcpy
, memset
, etc., you should consider compiling with -fno-builtin
option so that CLANG/GCC doesn't use its built in forms of the functions that may conflict with your own.如果您使用
-ffreestanding
进行编译并提供您自己的函数,例如memcpy
、 memset
等,您应该考虑使用-fno-builtin
选项进行编译,以便 CLANG/GCC 不使用可能与你自己。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.