我有个小问题。我有两个文件: one.c和two.c,它们都是decler并实现了struct: StackNode,头文件是: one.h:
#ifndef ONE_H
#define ONE_H
typedef struct StackNode StackNode;
#endif
二.h:
#ifndef TWO_H
#define TWO_H
#include "one.h"
#endif
cpp文件: one.c:
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>
#include "one.h"
struct StackNode
{
........
};
二.c:
#include <stdio.h>
#include <malloc.h>
#include "two.h"
struct StackNode
{
........
};
为什么这是在linox中编译和运行的,但在视觉上却是这样的: two.obj : error LNK2005:"struct StackNode * top“(?top@@3 3PAUStackNode@@A)已经定义在one.obj 1>c:\users\documents\visual studio 2010\Projects\Exercise\Debug\Exercise.exe :致命错误LNK1169:一个或多个已找到的乘法定义符号。
我能做什么,这样它也会在视觉上工作吗?谢谢您:)
发布于 2015-05-14 11:43:55
链接器没有说结构本身被定义了两次。它说对象top
被定义了两次,类似于struct StackNode * top
。您必须只在一个编译单元中定义它。
two.obj : error LNK2005:"struct StackNode * top“(?top@@3 3PAUStackNode@@A)已在one.obj中定义
https://stackoverflow.com/questions/30245743
复制相似问题