簡體   English   中英

錯誤:此處聲明的函數“ms_abi”先前是在未調用約定的情況下聲明的(clang)

[英]error: function declared 'ms_abi' here was previously declared without calling convention (clang)

當我嘗試編譯包含另一個 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.hsystemapi.h只是定義了 uintx_t 類型)

#pragma once

#define KABI __attribute__((ms_abi))

另一個包含string.hlibk.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

如果沒有您的構建環境,有根據的猜測是您正在重新定義具有與ms_abi函數屬性不兼容的原型的ms_abi函數。 如果您使用-ffreestanding進行編譯並提供您自己的函數,例如memcpymemset等,您應該考慮使用-fno-builtin選項進行編譯,以便 CLANG/GCC 不使用可能與你自己。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM