2011-11-17 34 views
12

Tôi biết bạn đã thấy 21728517 người yêu cầu trợ giúp về vấn đề này nhưng sau khi tìm kiếm và đọc về điều này tôi thực sự không thể tìm ra điều này. Tôi biết lỗi này, tôi đã nhìn thấy nó trước đây, tuy nhiên, lần này, tôi không thể có vẻ để có được xung quanh nó.LNK2005 (đã được xác định)

Tôi cũng đã thử điều này checklist.

Vì vậy, các lỗi:

Error 25 error LNK2005: "void __cdecl checkStatus(unsigned int &,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,bool)" ([email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected]) already defined in DollarRecognizer.obj C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty 

Error 26 error LNK2005: "void __cdecl depth2rgb(unsigned short const *,unsigned short *,char *,int,int)" ([email protected]@[email protected]) already defined in DollarRecognizer.obj C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty 

Error 27 error LNK2005: "class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > __cdecl explode(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,char)" ([email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@[email protected][email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@@[email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) already defined in DollarRecognizer.obj C:\Users\Rui Teixeira\Desktop\Current\Tese\SVN\TIFEE_Empty\TIFEE_Empty\main.obj TIFEE_Empty 

Vì vậy, vấn đề là, đây là những chức năng được xác định trong "misc.h" với #endif #ifndef #define thích hợp. Chúng không được xác định ở nơi khác nhưng tôi vẫn nhận được cái chết của LNK2005. Tôi đang làm gì sai?

Xin cảm ơn trước.

+5

#including tệp .h trong nhiều tệp .cpp sẽ kích hoạt lỗi trình liên kết này. Chỉ nên có * một * định nghĩa. Bạn có thể đặt * inline * ở phía trước nó. –

Trả lời

21

Xác định các chức năng trong misc.cpp, thay vì trong misc.h.

Sự cố có thể do #include ing misc.h trong nhiều tệp CPP. các tiêu đề bảo vệ ngăn chặn một tiêu đề được bao gồm nhiều lần trong cùng một đơn vị dịch, nhưng mỗi tệp CPP là (thường) một đơn vị dịch riêng biệt. Vì vậy, những chức năng đó sẽ được xác định hai lần - một lần trong mỗi đơn vị dịch.

+0

cũng là ngu ngốc của tôi. tôi đã có nó một .cpp riêng biệt trước đây. tôi phải thay đổi nó. cảm ơn bạn :) – takecare

Các vấn đề liên quan