ghostbody / 15-cpp-learning

15 c++ learning repository of SDCS SYSU
6 stars 3 forks source link

Want Help on a compile Problem #11

Open KatharinaLin opened 8 years ago

KatharinaLin commented 8 years ago

I have tried my best to find the problem for two days ,but failed. This is the report: /tmp/cccZdMj9.o: In function BooleanMatrix::BooleanMatrix(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition ofBooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::BooleanMatrix(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition ofBooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition ofBooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition ofBooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::replace(bool, int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:13: multiple definition ofBooleanMatrix::replace(bool, int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:13: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::operator&(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:21: multiple definition ofBooleanMatrix::operator&(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:21: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::operator|(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:28: multiple definition ofBooleanMatrix::operator|(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:28: first defined here /tmp/cccZdMj9.o: In function BooleanMatrix::BooleanProduct(BooleanMatrix const&) const': /home/lin/DS/main.cpp/BooleanMatrix.cpp:35: multiple definition ofBooleanMatrix::BooleanProduct(BooleanMatrix const&) const' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:35: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition ofBooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition ofBooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition ofBooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition ofBooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::replace(bool, int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:13: multiple definition ofBooleanMatrix::replace(bool, int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:13: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::operator&(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:21: multiple definition ofBooleanMatrix::operator&(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:21: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::operator|(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:28: multiple definition ofBooleanMatrix::operator|(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:28: first defined here /tmp/ccnYc5A0.o: In function BooleanMatrix::BooleanProduct(BooleanMatrix const&) const': /home/lin/DS/main.cpp/BooleanMatrix.cpp:35: multiple definition ofBooleanMatrix::BooleanProduct(BooleanMatrix const&) const' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:35: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition ofBooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::~BooleanMatrix()': /home/lin/DS/main.cpp/BooleanMatrix.cpp:6: multiple definition ofBooleanMatrix::BooleanMatrix(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:6: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition ofBooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::BooleanMatrix(int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:9: multiple definition ofBooleanMatrix::BooleanMatrix(int, int)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:9: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::replace(bool, int, int)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:13: multiple definition ofBooleanMatrix::replace(bool, int, int)' main.cpp.zip

/tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:13: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::operator&(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:21: multiple definition ofBooleanMatrix::operator&(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:21: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::operator|(BooleanMatrix const&)': /home/lin/DS/main.cpp/BooleanMatrix.cpp:28: multiple definition ofBooleanMatrix::operator|(BooleanMatrix const&)' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:28: first defined here /tmp/cckiKUTS.o: In function BooleanMatrix::BooleanProduct(BooleanMatrix const&) const': /home/lin/DS/main.cpp/BooleanMatrix.cpp:35: multiple definition ofBooleanMatrix::BooleanProduct(BooleanMatrix const&) const' /tmp/ccoVXdjj.o:/home/lin/DS/main.cpp/BooleanMatrix.cpp:35: first defined here collect2: error: ld returned 1 exit status lin@lin-VirtualBox:~/DS/main.cpp$

KatharinaLin commented 8 years ago

main.cpp.zip

ghostbody commented 8 years ago

@KatharinaLin multiple definition problem, please remember to add #program once or

#ifndef  HEADER_HPP_
#define HEADER_HPP_
// your class declaration
#endif
KatharinaLin commented 8 years ago

I just add #ifndef...into my digraph.cpp, others are with it before, but it did't work, the problem still exist.

KatharinaLin commented 8 years ago

virtualbox_25_19_04_2016_12_08_04

ghostbody commented 8 years ago

@KatharinaLin no need to add it in cpp files. I found that you file "Ralation.hpp" dose not have a definition protection.

KatharinaLin commented 8 years ago

I'm so sorry.Firstly I add "#ifndef"into Relation.hpp,but I forget "RELATION_HPP", It reported some mistakes to me but without the same problem of redefinition.So I thought it repaired.However, Linux Teminal just don't show me.When fixed the problems, redefinition problem show again.I don't know why they didn't appear at the same time .I'm so sad.

KatharinaLin commented 8 years ago

v

ghostbody commented 8 years ago

I can not get your point? What's exactly happened with you? =_=

Mensu commented 8 years ago

因为你在Relation.cpp和BooleanMatrix.cpp里都有那些函数的定义,编译器不知道要选哪个

BooleanMatrix.cpp里有那些函数不奇怪,但为什么Relation.cpp里也有那些函数的定义呢? 因为Relation.cpp里有#include "Relation.hpp", 于是Relation.cpp里出现了#include "BooleanMatrix.cpp" 于是Relation.cpp把那些函数的定义复制了进来,Relation.cpp里也就有了那些函数的定义

不妨试试

include "BooleanMatrix.cpp" 换成

include "BooleanMatrix.hpp"

在没有十足把握的情况下, 建议不要include一个cpp,特别是在这个cpp里有函数定义的时候 给每个hpp加上防止多次include的#ifndef XXX #define XXX ... #endif 是个好习惯 (我觉得你其他文件都做得挺好的啊,这里应该是不小心打错了吧)

KatharinaLin commented 8 years ago

@ghostbody It didn't work actually.

KatharinaLin commented 8 years ago

@Mensu I am trying now.Thank you.

KatharinaLin commented 8 years ago

@Mensu Yes, it's actually the problem.Thank you, I will remember it next time.