2017-12-27 695 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不使用可能與您自己衝突的函數的內置形式。

相關問題