奇怪的MFC/VC ++链接器错误(已定义std :: list) [英] Strange MFC / VC++ Linker Error (std::list already defined)

查看:111
本文介绍了奇怪的MFC/VC ++链接器错误(已定义std :: list)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个非常奇怪的错误消息,该错误消息仅在将以下行添加到我的项目中时发生:

std :: list< crect> myVar;
值得注意的是,它不必是std :: list,也可以是std :: vector或我假设的任何其他STL容器.

这是错误消息:

错误1错误LNK2005:"public:__thiscall std :: list

:: list>(void)(?0?$ list @ VCRect @@ V?$ allocator @ VCRect @@@ std @@@ std @@ QAE @ XZ)已在SomeLowLevelLibrary.lib
中定义
错误消息中引用的低级库不了解我正在构建的项目,它仅具有核心低级功能,不处理高级MFC GUI.

如果将代码行更改为:
,我可以消除链接器错误.
std :: list< crect *> myVar;
但我不想为此而乱砍.

另外,无论是在堆栈还是堆上创建变量都没关系,我仍然会遇到相同的错误.

有人对此有任何想法吗?我正在Vista Enterprise上使用Microsoft Visual Studio 2008 SP1.

上面的链接器错误是针对std :: list<>的.构造函数,析构函数_Nextnode和清除函数也会出错.

在项目中的其他文件中,std :: vector将不会链接,在其他文件中则可能是std :: list.我无法弄清楚为什么有些容器可以工作,而有些则不能. MFC链接在两个库之间都是静态的.在低级库中,我们有1个类继承自std :: list.

低级库没有任何继承自CRect的类,但是它确实使用了STL.

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.

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

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.

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

推荐答案

list @ VCRect @@ V?
list@VCRect@@V?


allocator @ VCRect @@@ std @@@ std @@ QAE @ XZ)已在SomeLowLevelLibrary.lib中定义

错误消息中引用的低级库不了解我正在构建的项目,它仅具有核心低级功能,不处理高级MFC GUI.

如果将代码行更改为:
,我可以消除链接器错误.
std :: list< crect *> myVar;
但我不想为此而乱砍.

另外,无论是在堆栈还是堆上创建变量都没关系,我仍然会遇到相同的错误.

有人对此有任何想法吗?我正在Vista Enterprise上使用Microsoft Visual Studio 2008 SP1.

上面的链接器错误是针对std :: list<>的.构造函数,析构函数_Nextnode和清除函数也会出错.

在项目中的其他文件中,std :: vector将不会链接,在其他文件中则可能是std :: list.我无法弄清楚为什么有些容器可以工作,而有些则不能. MFC链接在两个库之间都是静态的.在低级库中,我们有1个类继承自std :: list.

低级库没有任何继承自CRect的类,但是它确实使用了STL.
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.

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

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.

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


这很有趣.您所说的"hack"是唯一要做的事情.您会看到std::list不是一种类型.这是模板类型,需要使用类型参数实例化.您不能具有std::list的实例,可以具有std::list<int>std::list<std:string>等.

C ++编译器/链接器消息可能会引起误解.您可能使用了不同的名称.我有更明智的错误消息"Error 1 error C2955: ''std::list'' : use of class template requires template argument list".这很清楚.

您需要阅读有关C ++模板的信息才能在开发中使用STL库.

—SA
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


这篇关于奇怪的MFC/VC ++链接器错误(已定义std :: list)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆