fatal error LNK1169: 找到一个或多个多重定义的符号
本帖最后由 jsaac 于 2020-7-17 23:32 编辑想写一个顺序表创建程序
这是
creat_list.c文件:
#include<malloc.h>
#define elemtype int
#define Maxsize 20
typedef struct
{
elemtype data;
int length;
}int_list;
int_list* creat(){
int_list*point;
point=(int_list*)malloc(sizeof(int_list));
return point;
}
这是主函数文件:
#include<stdio.h>
#include<creat_list.c>
int main()
{
int_list* creat();
int_list*list_1;
list_1=creat();
printf("d%",sizeof(*list_1));
}
我想知道为什么报错啊!!!
Mainfile.obj : error LNK2005: _creat 已经在 creat_list.obj 中定义
1>C:\Users\Lenovo\Desktop\C-language\visual 2010\the first\Debug\List.exe : fatal error LNK1169: 找到一个或多个多重定义的符号
========== 生成: 成功 0 个,失败 1 个,最新 0 个,跳过 0 个 ==========
百度了很多答案,都看不懂、、、
请大神们帮我分析以下问题在哪,怎么解决,跪谢{:10_254:} 删了项目,重开一个。 永恒的蓝色梦想 发表于 2020-7-17 23:28
删了项目,重开一个。
我怀疑你在骗我的鱼币 jsaac 发表于 2020-7-17 23:29
我怀疑你在骗我的鱼币
这是解决这种问题最有效的方法,没有之一。 你需要增加一个 create_list.c 对应的 create_list.h 文件
函数声明写在 .h 文件,实现写在 .c 文件
在 create_list.c & main.c 两个 .c 文件中都通过
#include "create_list.h"
引用 .h 文件
----------------------------------------------------------
c 语言的#include 预编译指令本质上就是将目标文件全部拷贝到指令的位置,
create 函数在create_list.c 中有一份,又在 main.c 通过 #include “create_list.c" 包含一份,因此会提示重复定义符号。
以上。
赚小钱 发表于 2020-7-17 23:45
你需要增加一个 create_list.c 对应的 create_list.h 文件
函数声明写在 .h 文件,实现写在 .c 文件
感谢,我直接把creat_list.c文件删除了,并在头文件夹中新建了一个文件,内容不变,可以运行 沙发 kk 我也是{:5_90:} nayubi
页:
[1]