Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.
Posted

This is funny. What you say is "hack" is the only write thing to do. You see, std::list in not a type. This is template type, it needs to be instantiated with type parameter(s). You cannot have an instance of std::list, you can have std::list<int>, std::list<std:string>, etc.

C++ compiler/linker messages can be very misleading. You probably use different ones. I have more sensible error message "Error 1 error C2955: 'std::list' : use of class template requires template argument list". This is quite clear.

You need to read about C++ templates in order to use STL library in development.

—SA
 
Share this answer
 
Comments
[no name] 10-Mar-11 5:09am    
Thanks for reply but it not a complilar error its linking error.

as you say if std::list must with string or int then my app may not even complile.
but application get complile but have linking error
please read error.

thanks.
Sergey Alexandrovich Kryukov 10-Mar-11 5:30am    
I read your message. I'm telling you the reason (of course you do #include <list>, right?).
"std::list myVar;" at all. Do you want to insist to write a line like that? What's the meaning of it then?
--SA
I don't use STL much, but as far as I know list is a template class and you must specialize it if you want to use it:

std::list<YourTypeHere> myVar;
 
Share this answer
 
Probably you have the
#include <list>
defined in multiple header file. Make sure to include it only once.
 
Share this answer
 
Comments
[no name] 10-Mar-11 4:27am    
But obeous
i included this.
Ryan Zahra 10-Mar-11 4:28am    
Yes you need to include it. But you need to include it only once in the whole project!
[no name] 10-Mar-11 4:31am    
i included it in stdafx.h
only there is no repetation of this in whole code
Ryan Zahra 10-Mar-11 4:44am    
Did you include #pragma once in stdafx.h?
[no name] 10-Mar-11 4:55am    
yes i am included this also
at top of stdafx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900