我在写MFC中遇到重复编译的问题 无法解决 求各位帮助
首先第一个头文件
_____________________list.h
#include<stdio.h>
#include<String.h>
#include <stdlib.h>
#include <malloc.h>
#define maxsize 100
#define memsize 100000
#ifndef _LIST_H_ //先测试x是否被宏定义过
#define _LIST_H_
#pragma once
定义结构体 和链表
#endif
第二个文件
--------------------------------listop.h
#include<stdio.h>
#include<String.h>
#include <stdlib.h>
#include <malloc.h>
#ifndef _LISTOP_H_ //先测试x是否被宏定义过
#define _LISTOP_H_
#pragma once
定义对文件和结构体的操作
#endif
第三个文件
---------------------------------creatfile.cpp
#include "stdafx.h"
#include "操作系统课设.h"
#include "creatfile.h"
#include"list.h"
#include"listop.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
按钮的函数 调用头文件中的函数
第四个文件
——----------------------openfile.cpp
#include "stdafx.h"
#include "操作系统课设.h"
#include "openfile.h"
#include"list.h"
#include"listop.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
按钮的函数 调用头文件中的函数
编译出来的错误:
openfile.obj : error LNK2005: "void __cdecl getime(char *)" (?getime@@[email protected]) already defined in creatfile.obj
openfile.obj : error LNK2005: "void __cdecl writemen(void)" (?writemen@@YAXXZ) already defined in creatfile.obj
openfile.obj : error LNK2005: "void __cdecl readmenu(void)" (?readmenu@@YAXXZ) already defined in creatfile.obj
openfile.obj : error LNK2005: "int __cdecl searchmenu(class CString,int,int,int)" (?searchmenu@@YAHVCString@@[email protected]) already defined in creatfile.obj
openfile.obj : error LNK2005: "void __cdecl CreatList(struct DuLNode * &)" (?CreatList@@YAXAAPAUDuLNode@@@Z) already defined in creatfile.obj
openfile.obj : error LNK2005: "int __cdecl RequestList(struct DuLNode * &,int,int)" (?RequestList@@YAHAAPAUDuLNode@@[email protected]) already defined in creatfile.obj
openfile.obj : error LNK2005: "void __cdecl FreeList(struct DuLNode * &,int)" (?FreeList@@YAXAAPAUDuLNode@@[email protected]) already defined in creatfile.obj
openfile.obj : error LNK2005: "void __cdecl start(void)" (?start@@YAXXZ) already defined in creatfile.obj
openfile.obj : error LNK2005: "int __cdecl freemenu(class CString)" (?freemenu@@YAHVCString@@@Z) already defined in creatfile.obj
openfile.obj : error LNK2005: "int __cdecl judfilename(class CString)" (?judfilename@@YAHVCString@@@Z) already defined in creatfile.obj
openfile.obj : error LNK2005: "struct catalog * log" (?log@@3PAUcatalog@@A) already defined in creatfile.obj
openfile.obj : error LNK2005: "char * memory" (?memory@@3PADA) already defined in creatfile.obj
openfile.obj : error LNK2005: "struct menu me" (?me@@3Umenu@@A) already defined in creatfile.obj
openfile.obj : error LNK2005: "struct DuLNode * L" (?L@@3PAUDuLNode@@A) already defined in creatfile.obj
错误中的函数 结构体等都是在头文件中定义的 但是这里显示重复定义,请教各位如何解决这个问题
------解决方案--------------------
你最好用新建项目向导产生一个MFC控制台程序,再把你的代码拷贝进去。
------解决方案--------------------
c 的头文件是文件包含,不像c# ,多个文件同时引用一个,只会产生一份,c的话,可能会产生多份