I'm getting exactly the same problem.
It appears to occur only when I include standard library
components. The errors differ very slightly depending on
which standard #include files I use but are always a list
of LNK2020 unresolved tokens followed by a LNK1120.
I've tried putting #pragma unmanaged/managed statements in
a variety of different positions around both the standard
#include <> 's, the function prototypes and the function
bodies all to no avail.
---
Examples:
---
#include "stdafx.h"
#include <string>
#pragma unmanaged
class stltest
{
public:
int a;
int b;
std::string s;
};
#pragma managed
produces:
------ Build started: Project: mtest1, Configuration:
Debug Win32 ------
Compiling...
Stdafx.cpp
Compiling...
stltest.cpp
mtest1.cpp
AssemblyInfo.cpp
Generating Code...
Compiling resources...
Linking...
LINK : error LNK2020: unresolved token (0A000013)
_CxxThrowException
LINK : error LNK2020: unresolved token (0A000023) delete
LINK : fatal error LNK1120: 2 unresolved externals
---
Whereas moving the #pragma's around a little:
#include "stdafx.h"
#pragma unmanaged
#include <string>
class stltest
{
public:
int a;
int b;
std::string s;
};
#pragma managed
produces:
Compiling...
stltest.cpp
mtest1.cpp
Generating Code...
Linking...
mtest1.obj : error LNK2019: unresolved external symbol
_memcpy referenced in function "public: static char *
__cdecl std::char_traits<char>::copy(char *,char const
*,unsigned int)" (?copy@?
$char_traits@D@std@@SAPADPADPBDI@Z)
stltest.obj : error LNK2001: unresolved external symbol
_memcpy
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol _memcpy
mtest1.obj : error LNK2019: unresolved external symbol
_memmove referenced in function "public: static char *
__cdecl std::char_traits<char>::move(char *,char const
*,unsigned int)" (?move@?
$char_traits@D@std@@SAPADPADPBDI@Z)
stltest.obj : error LNK2001: unresolved external symbol
_memmove
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol _memmove
mtest1.obj : error LNK2019: unresolved external
symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z) referenced in function "public: void
__thiscall std::allocator<char>::deallocate(char
*,unsigned int)" (?deallocate@?
$allocator@D@std@@QAEXPADI@Z)
stltest.obj : error LNK2001: unresolved external
symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z)
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z)
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z)
mtest1.obj : error LNK2019: unresolved external symbol
___CxxFrameHandler referenced in function __ehhandler$?
_Copy@?$basic_string@DU?$char_traits@D@std@@V?
$allocator@D@2@@std@@IAEXII@Z
stltest.obj : error LNK2019: unresolved external symbol
___CxxFrameHandler referenced in function $L12690
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol ___CxxFrameHandler
mtest1.obj : error LNK2019: unresolved external symbol
__except_list referenced in function "protected: void
__thiscall std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >::_Copy
(unsigned int,unsigned int)" (?_Copy@?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@std@@IAEXII@Z)
stltest.obj : error LNK2001: unresolved external symbol
__except_list
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol __except_list
mtest1.obj : error LNK2019: unresolved external symbol
__CxxThrowException@8 referenced in function $L12724
stltest.obj : error LNK2001: unresolved external symbol
__CxxThrowException@8
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol __CxxThrowException@8
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol __CxxThrowException@8
mtest1.obj : error LNK2019: unresolved external symbol
_free referenced in function "void __cdecl
std::_DebugHeapDelete<void>(void *)" (??
$_DebugHeapDelete@X@std@@YAXPAX@Z)
stltest.obj : error LNK2001: unresolved external symbol
_free
libcpmtd.lib(xlock.obj) : error LNK2019: unresolved
external symbol _atexit referenced in function _$E1
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol _atexit
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol "public: __thiscall exception::exception
(class exception const &)" (??0exception@@QAE@ABV0@@Z)
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol "public: __thiscall exception::exception
(class exception const &)" (??0exception@@QAE@ABV0@@Z)
libcpmtd.lib(string.obj) : error LNK2001: unresolved
external symbol "const type_info::`vftable'" (??
_7type_info@@6B@)
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol "const type_info::`vftable'" (??
_7type_info@@6B@)
libcpmtd.lib(string.obj) : error LNK2019: unresolved
external symbol "public: virtual __thiscall
exception::~exception(void)" (??1exception@@UAE@XZ)
referenced in function $L12220
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol "public: virtual __thiscall
exception::~exception(void)" (??1exception@@UAE@XZ)
libcpmtd.lib(string.obj) : error LNK2019: unresolved
external symbol "public: __thiscall exception::exception
(void)" (??0exception@@QAE@XZ) referenced in
function "public: __thiscall std::logic_error::logic_error
(class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> > const
&)" (??0logic_error@std@@QAE@ABV?$basic_string@DU?
$char_traits@D@std@@V?$allocator@D@2@@1@@Z)
libcpmtd.lib(string.obj) : error LNK2019: unresolved
external symbol _strlen referenced in function "public:
static unsigned int __cdecl std::char_traits<char>::length
(char const *)" (?length@?$char_traits@D@std@@SAIPBD@Z)
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved
external symbol __malloc_dbg referenced in function "void
* __cdecl operator new(unsigned int,struct
std::_DebugHeapTag_t const &,char *,int)" (??
2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved
external symbol __free_dbg referenced in function "void
__cdecl operator delete(void *,struct std::_DebugHeapTag_t
const &,char *,int)" (??
3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
libcpmtd.lib(newop.obj) : error LNK2019: unresolved
external symbol __callnewh referenced in function "void *
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
libcpmtd.lib(newop.obj) : error LNK2019: unresolved
external symbol _malloc referenced in function "void *
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
libcpmtd.lib(nomemory.obj) : error LNK2001: unresolved
external symbol "public: virtual char const * __thiscall
exception::what(void)const " (?what@exception@@UBEPBDXZ)
libcpmtd.lib(nomemory.obj) : error LNK2019: unresolved
external symbol "public: __thiscall exception::exception
(char const * const &)" (??0exception@@QAE@ABQBD@Z)
referenced in function "public: __thiscall
std::bad_alloc::bad_alloc(char const *)" (??
0bad_alloc@std@@QAE@PBD@Z)
LINK : error LNK2001: unresolved external symbol
__load_config_used
---
Finally the following compiles quite happily (except for
complaining about a missing 'libc.pdb' file - LNK4099)
#include "stdafx.h"
#pragma unmanaged
//#include <string>
class stltest
{
public:
int a;
int b;
//std::string s;
};
#pragma managed
---
If anyone can shed any light on this I would be most
grateful.
Thanks,
Tom
-----Original Message-----
When I build a C++ library to .NET using the managed C++ compiler, I get the
following error message:
Linking...
LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport
LINK : error LNK2020: unresolved token (0A000007) memset
LINK : error LNK2020: unresolved token (0A000008) free
LINK : error LNK2020: unresolved token (0A00000A) atexit
LINK : error LNK2020: unresolved token (0A000028) wcscpy
LINK : error LNK2020: unresolved token (0A00002D) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000031) delete
LINK : error LNK2020: unresolved token (0A00003C) delete[]
LINK : error LNK2020: unresolved token (0A000045) malloc
LINK : error LNK2020: unresolved token (0A000049) memmove
LINK : error LNK2020: unresolved token (0A000054) memcpy
LINK : error LNK2020: unresolved token (0A000060) strlen
LINK : error LNK2020: unresolved token (0A000067) bad_cast.__ctor
LINK : error LNK2020: unresolved token (0A0000A6) exception.__dtor
LINK : error LNK2020: unresolved token (0A0000A7) exception.__ctor
LINK : error LNK2020: unresolved token (0A0000A8) exception.__ctor
LINK : fatal error LNK1120: 16 unresolved externals
Note that "Ignore All Default Libraries" is set to "No" and that the code
builds fine when using the unmanaged C++ compiler and targetting native
code. If I use the DLL version of the library, I get a slightly different
list of errors.
What should I do to get this to build correctly?
Thanks,
Aaron Queenan.
.