2017-12-27 698 views
2

当我尝试编译C代码,其中包括另一C头我得到这个错误以前声明:错误:函数声明“ms_abi”这里没有调用约定(铛)

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 

编译器是铛和涉及的文件如下:
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(类型定义刚刚定义uintx_t类型)

#pragma once 

#define KABI __attribute__((ms_abi)) 

另一个报头,其包括string.hlibk.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

+0

@MichaelPetch我改变了顺序,但什么都没有改变,同样的错误信息 – Rottenheimer2

+0

我在github上的项目创建一个分支,所以你可以看到更多的方面:https://github.com/TheStr3ak5/CKA/tree/TheStr3ak5- newABI,只要在BUILD文件后面建立这个分支,你就会看到错误。 – Rottenheimer2

+0

@MichaelPetch是的,你是对的,它解决了我的问题,谢谢! – Rottenheimer2

回答

2

而不必构建环境,一个受过教育的猜测是,你正在重新定义建立在具有与该ms_abi功能属性不相容的原型功能。如果您正在编译-ffreestanding并提供自己的函数,如memcpy,memset等,您应该考虑使用​​选项进行编译,以便CLANG/GCC不使用可能与您自己冲突的函数的内置形式。

相关问题