首页 > 解决方案 > C中同一行的“多个定义”

问题描述

所以我正在制作一个名为reboot的函数,但是当我定义它时,编译器会给出一个错误,就像函数已经定义一样。

这是bios.c:

#include "bios.h"
#include <stdint.h>
#include <libasm/asm.h>
void reboot()
{
    uint8_t good = 0x02;
    while (good & 0x02)
        good = EmeraldASM_inb(0x64);
    EmeraldASM_outb(0x64, 0xFE);
    asm volatile("hlt");
}

这是 bios.h :

#ifndef BIOSPOWER_H
#define BIOSPOWER_H
#pragma once
void reboot();
extern void shutdown();
#endif

这是编译器错误:/home/abbix/Documents/Projects/emerald/src/firmware/bios.c:5: multiple definition of `reboot'; src/firmware/bios.o:/home/abbix/Documents/Projects/emerald/src/firmware/bios.c:5: first defined here

这是我的Makefile:

https://pastebin.com/xCcQEtx3

标签: ckernel

解决方案


问题是我的程序集文件名为 bios.asm,因此它创建了两个 bios.o,这就是导致错误的原因(感谢 Eric Postpischil)


推荐阅读