“多重定义” C ++编译器错误 [英] "Multiple definition of" C++ compiler error

查看:203
本文介绍了“多重定义” C ++编译器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法摆脱这些看似随机的编译错误在我的一个类。
我得到大约4个错误,如:

 `draw_line(float,float,float,float) '

 code>````多重定义`near_far_clip(float,float,float *,float *,float *,float *,float *,float *)'


我也一直得到多重定义of'stack'在另一个方法的中间。 stack 是一个完全不同的文件中的全局变量。在文件中我甚至没有提到错误。



我试图将错误倾向的文件分为.h和.cpp文件(原来只是a .cpp),没有关于错误更改...



我没有重复的方法。我只有一个 #include of lines.h,并且在开头有一个 #ifndef 子句。所有这些错误都显示在.cpp文件中。



任何想法都可以吗?



获取代码:





lines.cpp是一个转换的.c文件从我的导师。我包括makefile,以防万一,因为我总是有它的问题。我也准确地注释了错误在文件中标记的位置,但它们看起来很随机,所以我不知道它是否特别重要。我放弃了.h文件,因为它不是解决任何或帮助。我相信没有它就会更容易找到错误。



这是请求的 main.cpp文件(没有.h)。






文件,因为我仍然收到:

 `draw_line(float,float,float,float) 

 ``多重定义`near_far_clip(float,float,float *,float *,float *,float *,float *,float *)'

错误,但是`stack'错误的多重定义现在位于ThreeD.cpp文件(并且现在通过注释标记)。 更新:此错误已修复,并且文件已修改为显示以下内容:





我搞砸了一些全局变量extern,但它似乎没有影响任何东西。

解决方案

为什么#include lines.cpp在ThreeD.cpp?这是非常不寻常的。



你的makefile想要lines.o,所以你要编译lines.cpp。在lines.cpp中定义的任何内容都将在lines.o和ThreeD.o中。



在lines.cpp中有一个有趣的注释:

 不要忘记将声明放在.h文件中。 

我认为教师希望你将lines.cpp分成.h和.cpp。 / p>

摘录自lines.cpp:

  / * .h文件或在lines.h * / 
/ *

线条图标题。

* /


void draw_line(float,float,float,float);
int near_far_clip(float,float,float *,float *,float *,float *,
float *,float *);

我怀疑这两个声明是唯一应该在lines.h中的。


I can't seem to get rid of these seemingly random compiles errors in one of my classes. I get about 4 errors such as:

multiple definition of `draw_line(float, float, float, float)'

and

multiple definition of `near_far_clip(float, float, float*, float*, float*, float*, float*, float*)'

that are flagged in the middle of the method.

I also consistently get multiple definition of `stack' in the middle of another method. stack is a global variable in a totally different file. It isn't even mentioned in the file I'm getting the error in.

I tried separating the error prone file into .h and .cpp files (was originally just a .cpp) and nothing about the error changed...

I don't have duplicate methods. I only have one #include of lines.h and there is an #ifndef clause at the beginning. All these errors appear in the .cpp file.

Any ideas what it could be?

Alright, I got the code up:

The lines.cpp is a converted .c file I received from my instructor. I included the makefile just in case, because I always have problems with it. I also annotated exactly where the errors were flagged in the file, but they seem pretty random so I don't know if it's particularly important. I abandoned the .h file because it wasn't solving anything or helping. I believe it will be easier to find the mistake without it.

Here is the requested main.cpp file (there is no .h).


I remade the lines.h file due to and I'm still receiving the:

multiple definition of `draw_line(float, float, float, float)'

and

multiple definition of `near_far_clip(float, float, float*, float*, float*, float*, float*, float*)'

errors in the lines.cpp file, but the multiple definition of `stack' error is now in a random place in the ThreeD.cpp file (and is marked by a comment now). Update: This error has been fixed and the files have been revised to show this:

I messed around with labeling some the global variables extern, but it didn't seem to affect anything.

解决方案

Why do you #include lines.cpp in ThreeD.cpp? This is very unusual.

Your makefile wants lines.o, so you're going to compile lines.cpp. Anything defined in lines.cpp will be in lines.o and also in ThreeD.o.

There is an intriguing comment in lines.cpp:

Don't forget to put declarations in your .h files.

I think the instructor wants you to break lines.cpp into a .h and a .cpp.

Excerpt from lines.cpp:

/* These go in your .h file or in lines.h */
/*

Line drawing header.

*/


void draw_line(float, float, float, float);
int near_far_clip(float, float, float *, float *, float *, float *,
                  float *, float *);

I suspect that these two declarations are the only thing that should be in lines.h.

这篇关于“多重定义” C ++编译器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆