c - 头文件未正确包含

标签 c operating-system

不包括头文件 (stdint.h)。我知道后面有很多代码,但我真的不知道。

我的文件:

gdt.c

/* We need 8 segments */
#include <stdint.h>
#include "gdt.h"
#define GDT_SIZE 8
uint32_t intr;

gdt_entry gdtable[GDT_SIZE];

包含/gdt.h

#ifndef GDT_H
#define GDT_H
#include <stdint.h>
struct gdt_entry{
    uint_16t limit;
    uint_32t base :24;
    uint_32t accessbyte :8;
    uint_32t limit2 :4;
    uint_32t flags2 :4;
    uint_32t base2 :8;
}__attribute__((packed));
#endif

包含/stdint.h

#ifndef STDINT_H
#define STDINT_H

typedef unsigned long long uint64_t;
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
typedef unsigned char uint8_t;

typedef signed long long int64_t;
typedef signed int int32_t;
typedef signed short int16_t;
typedef signed char int8_t;

#endif

生成文件:

SRCS = $(shell find -name '*.[cS]')
OBJS = $(addsuffix .o,$(basename $(SRCS)))

CC = gcc
LD = ld

ASFLAGS = -m32
CFLAGS = -m32 -Wall -g -fno-stack-protector -I include
LDFLAGS = -melf_i386 -Tkernel.ld

kernel: $(OBJS)
    $(LD) $(LDFLAGS) -o $@ $^

%.o: %.c
    $(CC) $(CFLAGS) -c -o $@ $^

%.o: %.S
    $(CC) $(ASFLAGS) -c -o $@ $^

clean:
    rm $(OBJS)

.PHONY: clean

内核.ld

/*  start should be executed first */
ENTRY(_start)

/*
 * thats how the sections should be written in the .elf binary
 */
SECTIONS
{
    /*
     * the first section has a 1MB Offset for the grub bootloader
     */
    . = 0x100000;

     /*
      * the multiboot header comes first
      */
     .text : {
         *(multiboot)
         *(.text)
     }
     .data ALIGN(4096) : {
         *(.data)
     }
     .rodata ALIGN(4096) : {
         *(.rodata)
     }
     .bss ALIGN(4096) : {
         *(.bss)
     }
}

gcc 输出:

gcc -m32 -c -o start.o start.S
gcc -m32 -Wall -g -fno-stack-protector -I include -c -o gdt.o gdt.c
In file included from gdt.c:3:0:
include/gdt.h:5:2: error: unknown type name ‘uint_16t’
include/gdt.h:6:2: error: unknown type name ‘uint_32t’
include/gdt.h:7:2: error: unknown type name ‘uint_32t’
include/gdt.h:8:2: error: unknown type name ‘uint_32t’
include/gdt.h:9:2: error: unknown type name ‘uint_32t’
include/gdt.h:10:2: error: unknown type name ‘uint_32t’
gdt.c:7:1: error: unknown type name ‘gdt_entry’
make: *** [gdt.o] Error 1

最佳答案

我认为您应该使用 uint32_t 而不是非标准的 uint_32t。这至少是我遇到的第三个变体,之前我也见过 u_int32_t

关于c - 头文件未正确包含,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11392650/

相关文章:

c - 如何在C中打印出字符串的单个字符

Objective-C,如何将文件名传递给 C 函数?

c++ - 指针间接检查无效内存访问和段错误

c - 如何管理插入和删除内容的内存?

linux - 上下文切换的开销是多少?

process - 内核栈有什么用?

c - 更新使用 "-Bsymbolic"链接器选项生成的 ELF 共享对象

C 程序能否获取鼠标在 Windows 控制台中悬停的字符?

c - 函数参数中的*和&有什么区别?

c# - 在C#中检测windows 2008 server和windows 2003 server