简体   繁体   English

错误:此处声明的函数“ms_abi”先前是在未调用约定的情况下声明的(clang)

[英]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.hsystemapi.h只是定义了 uintx_t 类型)

#pragma once

#define KABI __attribute__((ms_abi))

Another header that includes string.h , libk.h另一个包含string.hlibk.hlibk.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进行编译并提供您自己的函数,例如memcpymemset等,您应该考虑使用-fno-builtin选项进行编译,以便 CLANG/GCC 不使用可能与你自己。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不调用声明的函数的情况下修改局部静态变量? - How to modify a local static variable without calling the function where it is declared? 调用头文件中声明的函数 - calling a function declared in header file 为什么未显示在声明之前调用函数的错误? - Why the error of - calling the function before being declared, is not shown? 使用太少的参数调用隐式声明的函数:为什么没有链接器错误? - Calling implicitly declared function with too few arguments: why there is no linker error? 如何强制cdecl调用约定在特定头文件中声明的函数 - How to force cdecl calling convention for functions declared in specific header file 调用在当前函数下声明的函数 - Calling a function which is declared under the current function 错误:函数内部未声明变量 - error: variable not declared inside function 如何在不丢失其属性的情况下声明先前在包含的库中声明的变量? - How to declare variables previously declared in included libraries without losing their attributes? C-调用带有无参数的参数声明的函数吗? - C - Calling a function declared with parameters with no parameters? 调用隐式声明的 function 时的意外行为 - Unexpected behavior when calling implicitly declared function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM