Issues with a C++ Test Project in Visual Studio 2010

ⅰ亾dé卋堺 提交于 2019-12-11 18:51:42

问题


I have been having problems making a C++ Test Project work in Visual Studio 2010. I am looking for what is wrong/what to do about it.

This kind of test project has to be compiled as managed code. No problem. C++ can be built that way. I did it this trivial example std::list example. I created a C++ CLR project. I pasted this code in and compiled. I can step through the code as it runs. It works.

 #include "stdafx.h"
 #include <list>

using namespace System;

int main(array<System::String ^> ^args)
{
    std::list<int> list;
    list.push_back(1);

    int& pt = list.front();
    list.pop_front();

    return 0;
}

I started over with a new C++ Test project. Because this is C++ code, I went to the project's properties > Configuration Properties > C/C++ > General > Common Language RunTime Support, and changed /clr:safe to /clr.

I created a basic test named ListTests and pasted the same code in a test named ListTest(). I get this when I build.

1>ListTests.obj : error LNK2028: unresolved token (0A0000E9) "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ) referenced in function "public: class std::_List_const_iterator<class std::_List_val<int,class std::allocator<int> > > & __thiscall std::_List_const_iterator<class std::_List_val<int,class std::allocator<int> > >::operator++(void)" (??E?$_List_const_iterator@V?$_List_val@HV?$allocator@H@std@@@std@@@std@@$$FQAEAAV01@XZ)
1>ListTests.obj : error LNK2019: unresolved external symbol "extern "C" int __cdecl _CrtDbgReportW(int,wchar_t const *,int,wchar_t const *,wchar_t const *,...)" (?_CrtDbgReportW@@$$J0YAHHPB_WH00ZZ) referenced in function "public: class std::_List_const_iterator<class std::_List_val<int,class std::allocator<int> > > & __thiscall std::_List_const_iterator<class std::_List_val<int,class std::allocator<int> > >::operator++(void)" (??E?$_List_const_iterator@V?$_List_val@HV?$allocator@H@std@@@std@@@std@@$$FQAEAAV01@XZ)

The problem appears whenever iterators are used. For example, if I comment out the last two lines - the ones that use front() and pop_front(), all is well. These methods use iterators internally.

If I change to boost, everything is fine. E.G. I can use boost::intrusive::list in a more complex function. It works fine.

Thoughts?

来源:https://stackoverflow.com/questions/51834198/issues-with-a-c-test-project-in-visual-studio-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!