[問題] VisualStudio檔案路徑設定 & 編譯錯誤訊息

看板C_and_CPP (C/C++)作者 (兌現承諾)時間16年前 (2010/05/24 17:30), 編輯推噓0(0018)
留言18則, 3人參與, 最新討論串1/1
我用的編譯器是visual studio 2010 寫了一個project包含數個標頭檔與cpp檔 project檔案太多,實在不知怎麼po上網 只好請大家直接幫我看看錯誤訊息, 猜猜哪裡出了錯.非常謝謝. 錯誤訊息如下 1>------ Rebuild All started: Project: Rod, Configuration: Debug Win32 ------ 1> main.cpp 1> RotationMatrix.cpp 1> EulerAngle.cpp 1> Bacillus.cpp 1> Generating Code... 1>RotationMatrix.obj : error LNK2005: "public: void __thiscall Quaternion::SetInitialValue(double,double,double)" (?SetInitialValue@Quaternion@@QAEXNNN@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "void __cdecl W_Matrix(class std::vector<class std::vector<double,class std::allocator<double> >,class std::allocator<class std::vector<double,class std::allocator<double> > > > &,class Quaternion)" (?W_Matrix@@YAXAAV?$vector@V?$vector@NV?$allocator@N@std@@@std@@V?$allocator@V?$vector@NV?$allocator@N@std@@@std@@@2@@std@@VQuaternion@@@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "void __cdecl W_Transverse(class std::vector<class std::vector<double,class std::allocator<double> >,class std::allocator<class std::vector<double,class std::allocator<double> > > > &,class Quaternion)" (?W_Transverse@@YAXAAV?$vector@V?$vector@NV?$allocator@N@std@@@std@@V?$allocator@V?$vector@NV?$allocator@N@std@@@std@@@2@@std@@VQuaternion@@@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: double __thiscall Vector3::magnitude(void)" (?magnitude@Vector3@@QAENXZ) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: double __thiscall Vector3::magnitude2(void)" (?magnitude2@Vector3@@QAENXZ) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: class Vector3 __thiscall Vector3::operator+(class Vector3 const &)" (??HVector3@@QAE?AV0@ABV0@@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: class Vector3 __thiscall Vector3::operator-(class Vector3 const &)" (??GVector3@@QAE?AV0@ABV0@@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: class Vector3 __thiscall Vector3::operator*(double)" (??DVector3@@QAE?AV0@N@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: class Vector3 __thiscall Vector3::operator/(double)" (??KVector3@@QAE?AV0@N@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: class Vector3 & __thiscall Vector3::operator=(class Vector3)" (??4Vector3@@QAEAAV0@V0@@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "public: class Vector3 & __thiscall Vector3::operator+=(class Vector3)" (??YVector3@@QAEAAV0@V0@@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "double __cdecl Dot(class Vector3 &,class Vector3 &)" (?Dot@@YANAAVVector3@@0@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "class Vector3 __cdecl Cross(class Vector3 &,class Vector3 &)" (?Cross@@YA?AVVector3@@AAV1@0@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "double __cdecl sign(double,double)" (?sign@@YANNN@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "double __cdecl max(double,double)" (?max@@YANNN@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "double __cdecl min(double,double)" (?min@@YANNN@Z) already defined in Bacillus.obj 1>RotationMatrix.obj : error LNK2005: "void __cdecl SinCos(double *,double *,double)" (?SinCos@@YAXPAN0N@Z) already defined in Bacillus.obj 1>c:\users\luckychild137\documents\visual studio 2010\Projects\Rod\Debug\Rod.exe : fatal error LNK1169: one or more multiply defined symbols found ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.11.75

05/24 17:55, , 1F
根據我的猜測,大概是沒用 header guard,或把不該存在於
05/24 17:55, 1F

05/24 17:55, , 2F
header file 中的定義式擺在 header file 造成的。
05/24 17:55, 2F

05/24 17:56, , 3F
C/C++ 都是只允許重複宣告但不允許重複定義的語言。
05/24 17:56, 3F

05/24 18:15, , 4F
我有header guard,也許是你說的第2種可能 謝謝你
05/24 18:15, 4F

05/24 21:42, , 5F
還是找不到耶 ~.~
05/24 21:42, 5F

05/24 22:02, , 6F
那我這樣問好了,你的
05/24 22:02, 6F

05/24 22:03, , 7F
void Quaternion::SetInitialValue() { ... } 這個實作碼
05/24 22:03, 7F

05/24 22:03, , 8F
寫在什麼檔案裡?
05/24 22:03, 8F

05/24 22:17, , 9F
Hello,謝謝你的回覆 我晚點再回應你 累了 先回家休息
05/24 22:17, 9F

05/24 22:18, , 10F
再聯絡吧!如果你有興趣的話,我再設法把檔案給妳看看
05/24 22:18, 10F

05/25 14:25, , 11F
我剛剛做了一件事 把對應A.h的cpp檔 A.cpp的內容搬到
05/25 14:25, 11F

05/25 14:27, , 12F
A.h 如此project就不用載入A.cpp 結果就好了
05/25 14:27, 12F

05/25 14:28, , 13F
所以我猜測是檔案路徑設定問題嗎?
05/25 14:28, 13F

05/25 14:28, , 14F
再繼續試試看
05/25 14:28, 14F

05/25 14:35, , 15F
好像真的是路徑問題耶...
05/25 14:35, 15F

05/25 14:36, , 16F
visual studio 2010 source file的路徑該怎設定呢?
05/25 14:36, 16F
※ 編輯: luckychild 來自: 140.120.11.75 (05/25 14:37)

05/25 23:08, , 17F
這應該是重覆定義了吧,你在.h裡有定義東西,然後這個.h又被
05/25 23:08, 17F

05/25 23:09, , 18F
多個.h或.cpp include
05/25 23:09, 18F
文章代碼(AID): #1B-aSk3K (C_and_CPP)
文章代碼(AID): #1B-aSk3K (C_and_CPP)