Uefi Protocol : error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Print3Hello’

Uefi Protocol : error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Print3Hello’

我正在尝试编写一个基于 Print2 协议的简单 UEFI 协议。

这里是整个编译错误:

Building ... /home/qwn/src/edk2/Print3/Print3.inf [X64]
"gcc" -g -fshort-wchar -fno-builtin -fno-strict-aliasing -Wall -Werror -Wno-array-bounds -ffunction-sections -fdata-sections -include AutoGen.h -fno-common -DSTRING_ARRAY_NAME=Print3Strings -m64 -fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -maccumulate-outgoing-args -mno-red-zone -Wno-address -mcmodel=small -fpie -fno-asynchronous-unwind-tables -Wno-address -flto -DUSING_LTO -Os -D DISABLE_NEW_DEPRECATED_INTERFACES -c -o /home/qwn/src/edk2/Build/MdeModule/DEBUG_GCC5/X64/Print3/Print3/OUTPUT/./Print3.obj -I/home/qwn/src/edk2/Print3 -I/home/qwn/src/edk2/Build/MdeModule/DEBUG_GCC5/X64/Print3/Print3/DEBUG -I/home/qwn/src/edk2/MdePkg -I/home/qwn/src/edk2/MdePkg/Include -I/home/qwn/src/edk2/MdePkg/Include/X64 -I/home/qwn/src/edk2/MdeModulePkg -I/home/qwn/src/edk2/MdeModulePkg/Include /home/qwn/src/edk2/Print3/Print3.c
/home/qwn/src/edk2/Print3/Print3.c:5:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Print3Hello’
 Print3Hello()
 ^

/home/qwn/src/edk2/Print3/Print3.c:12:3: error: ‘Print3Hello’ undeclared here (not in a function)
 Print3Hello
 ^

/home/qwn/src/edk2/Print3/Print3.c:20:1: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘Print3Entry’
 Print3Entry(
 ^

GNUmakefile:411: recipe for target '/home/qwn/src/edk2/Build/MdeModule/DEBUG_GCC5/X64/Print3/Print3/OUTPUT/Print3.obj' failed
make: *** [/home/qwn/src/edk2/Build/MdeModule/DEBUG_GCC5/X64/Print3/Print3/OUTPUT/Print3.obj] Error 1

这是主要的 .c 文件

#include "Print3.h"

EFI_STATUS
EFIAPT
Print3Hello()
{
  Print(L"Hello, self defined print3 protocol \n");
  return EFI_SUCCESS; 
}

EFI_PRINT3_PROTOCOL myPrint3Protocol = {
  Print3Hello
};

//Entry function for the driver, here we install the protocol  
EFI_HANDLE print3ProtocolHandle = NULL;

EFI_STATUS
EFIAPT
Print3Entry(
  EFI_HANDLE       imageHandle,
  EFI_SYSTEM_TABLE *systemTable
)
{
  EFI_STATUS status;

  status = gBS->InstallProtocolInterface(&print3ProtocolHandle,
                                         &gEfiPrint3ProtocolGuid,
                                         &myPrint3Protocol,
                                         NULL
                                         );
  ASSERT_EFI_ERROR (status);
  reutrn status;
}

这是.h

#ifndef _PRINT3_H_
#define _PRINT3_H_

#include <Uefi.h>
#include <Library/UefiLib.h>
#include <Library/UefiDriverEntryPoint.h>
#include <Library/UefiBootServicesTableLib.h>


//Guid for the print 3 protocol.
#define EFI_PRINT3_PROTOCOL_GUI \
  { 0x3b777e4b, 0x93b1, 0x4985, { 0xb0, 0x55, 0x52, 0x55, 0x1b, 0x54, 0xcc, 0xcc }}

typedef
EFI_STATUS
(EFIAPI *EFI_PRINT_STRING)();


typedef struct _EFI_PRINT3_PROTOCOL {
  EFI_PRINT_STRING efiPrintHello;
}EFI_PRINT3_PROTOCOL;

extern EFI_GUID gEfiPrint3ProtocolGuid;
#endif

最后是 inf

[Defines]
 INF_VERSION                    = 1.25
 BASE_NAME                      = Print3
 FILE_GUID                      = f4df2436-242b-4e13-ae42-50c30118eff2
 MODULE_TYPE                    = UEFI_DRIVER
 VERSION_STRING                 = 1.0
 ENTRY_POINT                    = Print3Entry


[Sources]
        Print3.h
        Print3.c

[Packages]
        MdePkg/MdePkg.dec
        MdeModulePkg/MdeModulePkg.dec

[LibraryClasses]
        UefiLib
        UefiDriverEntryPoint
        UefiBootServicesTableLib

[Guids]

[Ppis]

[Protocols]
        gEfiPrint3ProtocolGuid

[FeaturePcd]

[Pcd]

Print3 的 GUID 在 MdeModule/MdeModule.dec

中定义
## Print3/Print3.h
gEfiPrint3ProtocolGuid = { 0x3b777e4b, 0x93b1, 0x4985, { 0xb0, 0x55, 0x52, 0x55, 0x1b, 0x54, 0xcc, 0xcc }}

我遵循了 UEFi 库中实现的 Print2 协议。 inf 文件来自 print2.inf,但我生成的 GUID 除外,我更改了变量名称。

headers 已在 Print2 协议中使用。我想念的一定是非常愚蠢的东西

好吧,您稍后可能会发现另一个错误,但您得到的错误看起来像是因为宏 EFIAPT 未定义。我想你是说 EFIAPI。