English 中文(简体)
处理多重定义错误[封闭]
原标题:Getting multiple definition error [closed]

I m试图汇编一些C++文档。 在连接阶段时发现以下类型的错误。 (汇编工作) -


Main.o: In function operator<<(std::basic_ostream<char, std::char_traits<char> >&, Set const&) :
/usr/include/c++/4.3/new:105: multiple definition of
operator<<(std::basic_ostream< char, std::char_traits >&, Set const&) bundleXX.o:/xxx/DATASTRUCTURES/SET/set.h:162: first defined h ere

Main.o: In function print(std::basic_string<char, std::char_traits<char>, std::allo cator<char> >, int) :
/xxx/misc.h:28: multiple definition of
print(std::basic_string, std::allocator >, int) bundleXX.o:/xxx/misc.h:28: first defined here


该代码以前正确链接。 只是在我试图将这一守则与一些其他穿透的法典相连接的时候。

My makefile is this :-
Makefile


SRC = Main.C Bundle.C bundleXX.C BMinQuad.C MinQuad.C QPBundle.C OBJ = Main.o Bundle.o MinQuad.o BMinQuad.o QPBundle.o bundleXX.o general_includes.o CCC = g++ EXE = main OPT = -O3 -fomit-frame-pointer -fno-strict-aliasing DEBUG = -g -DDEBUG

IFLAGS = -I /xxx/ -I /xxx/DATASTRUCTURES/HEAP/ -I /xxx/DATASTRUCTURES/ LFLAGS = -lm

Main.o: $(SRC) $(CCC) $(DEBUG) $(LFLAGS) -I /xxx/ -I /xxx/DATASTRUCTURES/ -c $(SRC)

main: $(OBJ) $(CCC) $(OBJ) -I /xxx/ -I /xxx/DATASTRUCTURES/ -o $(EXE) /bin/rm -rf main.o

clean: /bin/rm -rf main.o /bin/rm -rf $(EXE) touch out.out /bin/rm -rf *.out


我非常赞赏一些帮助。

增 编

Edit: I tried inlining but it didn t work. I finally minimized the number of times I was including my code in the new code and it finally linked correctly. I think it might have been a case of recursive includes. 增 编 for the help though.

问题回答

是否界定了印刷(原版:插图、内装)和操作设计;以及 界定了主人内部的职能,你在多个C档案中都包含这些职能。

在担任上述职务之前尝试增加标题,或确定您之一的职能。 C 您正在链接起来。

Edit: Your edit mentioned you are doing "recursive" includes: Do you have #ifdef guards around your include files? This will prevent the same translation unit from including the same header multiple times.

#ifndef __MY_FILENAME_H_
#define __MY_FILENAME_H_
// your header details
#endif // End of the file...

只要其独一无二,其定义就毫无意义。 只是遵循某种标准。

链接阶段的多重定义几乎是always。 由于在头版档案中有密码,但我不敢肯定,这里的情况就是这样。

查阅<编码>xxx/DATASTRUCTIONS/SET/set.h和<编码>xxx/misc.h第28条。 (给他们留下几个方面,以便进一步帮助。)

这似乎是冲突发生地,以你重新获得的信息为基础。 您的新手脚很可能是,你与你目前的一些手脚有某种名称。

misc.h and set.h 您是否确实界定了联系人错误中提到的职能,或只是宣布这些职能为麻烦?

如果你实际界定这些定义,(即如果你实际执行职能机构),那么你在联系阶段就可能遇到多重定义问题。 您也可在一份单独的<代码>cpp文档中加以界定,也可在关键词上宣布使用inline。 如果它们的职能非常短,那么后一种选择就会更好。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?