Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange MFC / VC++ Linker Error (std::list<CRect> already defined)

I've got a really odd error message that only occurs when I add the following line to my project:

std::list<CRect> myVar;

It's worth noting that it doesn't have to be a std::list, it can be std::vector or any other STL container I assume.

Here is the error message:

Error 1 error LNK2005: "public: __thiscall std::list

::list >(void)" (??0?$list@VCRect@@V?$allocator@VCRect@@@std@@@std@@QAE@XZ) already defined in SomeLowLevelLibrary.lib

The low level library that's referenced in the error message has no idea about the project I am building, it only has core low level functionality and doesn't deal with high level MFC GUIs.

I can get the linker error to go away if I change the line of code to:

std::list<CRect*> myVar;

But I don't want to hack it for the sake of it.

Also, it doesn't matter if I create the variable on the stack or the heap, I still get the same error.

Does anyone have any ideas whatsoever about this? I'm using Microsoft Visual Studio 2008 SP1 on Vista Enterprise.

Edit: The linker error above is for the std::list<> constructor, I also get an error for the destructor, _Nextnode and clear functions.

Edit: In other files in the project, std::vector won't link, in other files it might be std::list. I can't work out why some containers work, and some don't. MFC linkage is static across both libraries. In the low level library we have 1 class that inherits from std::list.

Edit: The low level library doesn't have any classes that inherit from CRect, but it does make use of STL.

like image 421
Mark Ingram Avatar asked Feb 24 '26 17:02

Mark Ingram


1 Answers

You should be looking at the linker settings, but I can't immediately say which. It's normal for STL instantiations to be done in multiple files. The linker should pick one. They're all identical (assuming you do have consistent compiler settings).

like image 164
MSalters Avatar answered Feb 27 '26 03:02

MSalters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!