小编Cas*_*ray的帖子

C多重定义/首先在此定义错误

我正在尝试写一个书店程序,我在我的函数实现的源代码文件中收到一条错误"多重定义".

这是我的Book.c文件:

#include "Book.h"

void scanBook(book_t* bk) //error here
{
    //implementation here
}
Run Code Online (Sandbox Code Playgroud)

这是我的Book.h文件:

#pragma once
#include <stdio.h>

typedef char* str;    
typedef enum Genre {Education, Business, Novel} genre_t;

typedef struct Book{
    str ISBN;
    str title;
    str author;
    float price;
    int quantity;
    genre_t genre;
} book_t;

void scanBook(book_t* bk);
Run Code Online (Sandbox Code Playgroud)

这是我的main.c文件:

#include "Book.h"
#include "Book.c"

int main()
{
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

该错误发生在Book.c中的scanBook函数但我不知道为什么,因为我包括头文件以及#pragma一次,并在头文件中我声明了该函数.它说'scanBook'和obj\Debug\Book.o ....的多个定义首先在这里定义.

任何帮助或澄清将不胜感激!

c multiple-definition-error modularization

2
推荐指数
1
解决办法
9973
查看次数