C:对内联函数的未定义引用

C: undefined reference to inline function

由于我的上一个问题由于错误的代码风格和拼写错误而被关闭,我重新审阅并寻求帮助。

我正在尝试解析 PE 格式的 .exe 文件。这是我的部分代码

    #include "PE_resolve.h"
    #define SIZEOF_SECTION_HEADER 0x28

     /*load filebuffer into Imagebuffer*/
    int Read_2_ImageBuffer(void **p_filebuffer, void **p_Imagebuffer,long filesize);
    
    /*helper function*/
    inline void * Get_NT_POS(void **p_filebuffer);
    inline void * Get_FileHeader_POS(void **p_filebuffer);
    inline void * Get_Opt_FileHeader_POS(void **p_filebuffer);

    
    int main(){
        return 0;
    }

    int Read_2_ImageBuffer(void **p_filebuffer, void **p_Imagebuffer,long filesize){
       /*allocate memory for imagebuffer*/
       void *Opt_PE_Header = Get_Opt_FileHeader_POS(p_filebuffer); //THE ERROR LINE
       DWORD SizeOfImage = *(DWORD*) ((BYTE *)Opt_PE_Header + 0x38);
       *p_Imagebuffer = malloc(SizeOfImage);
        if(*p_Imagebuffer == NULL){
            printf("can't allocate enough heap memory\n");
            exit(EXIT_FAILURE);
        }
        memset(*p_Imagebuffer,0,SizeOfImage);
    
       /*.....something deal the memory.....*/
       return 0;
    }

    inline void * Get_NT_POS(void **p_filebuffer){
        /*return void * point to NT_header in filebuffer*/
        DWORD offset = *(DWORD*)((BYTE *)*p_filebuffer + 0x3c);
        return (BYTE *)*p_filebuffer + offset;
    }

    inline void * Get_FileHeader_POS(void **p_filebuffer){
         /*return void * point to PE_header in filebuffer*/
         void *nt_pos = Get_NT_POS(p_filebuffer);
         return (BYTE *)nt_pos + sizeof(DWORD);
    }
 
    inline void * Get_Opt_FileHeader_POS(void **p_filebuffer){
        /*return void * point to option_PE_header in filebuffer*/
        void *fileheader_pos = Get_FileHeader_POS(p_filebuffer);
        return (BYTE *)fileheader_pos + 0x14; 
    }

这是PE_resolve.h

#ifndef __PE_resolve_header
#define __PE_resolve_header
#define IMAGE_SIZEOF_SHORT_NAME 8

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef char BYTE; 
typedef short WORD;
typedef int DWORD;

typedef struct _IMAGE_SECTION_HEADER {
    BYTE Name[IMAGE_SIZEOF_SHORT_NAME];
    union {
        DWORD PhysicalAddress;
        DWORD VirtualSize;
    } Misc;
    DWORD VirtualAddress;
    DWORD SizeOfRawData;
    DWORD PointerToRawData;
    DWORD PointerToRelocations;
    DWORD PointerToLinenumbers;
    WORD NumberOfRelocations;
    WORD NumberOfLinenumbers;
    DWORD Characteristics;
} _IMAGE_SECTION_HEADER;

#endif

当我用 MinGW 编译它时,它后面跟着对 `Get_Opt_FileHeader_POS'

的未定义引用
C:\MinGW\bin\gcc.exe -g D:\Compile\PE_resolve\PE_loader.c -o D:\Compile\PE_resolve\PE_loader.exe
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: C:\Users205\AppData\Local\Temp\ccadB6tt.o: in function `Read_2_ImageBuffer':
D:/Compile/PE_resolve/PE_loader.c:52: undefined reference to `Get_Opt_FileHeader_POS'

如你所见,我在这个.c文件中实现了所有函数,原型都在开头。 我有点沮丧。你能告诉我导致错误的原因吗? 谢谢:(

您可以在每个内联函数之前添加 static 关键字。
通过这样做,您可以强制链接器在符号 table:

中包含函数符号
static inline void *Get_Opt_FileHeader_POS(void **p_filebuffer);

另一种选择是简单地删除内联关键字。