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.cp p
Generating Code...
Compiling resources...
Linking...
LINK : error LNK2020: unresolved token (0A000013)
_CxxThrowExcept ion
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_trait s<char>::copy(c har *,char const
*,unsigned int)" (?copy@?
$char_traits@D@ std@@SAPADPADPB DI@Z)
stltest.obj : error LNK2001: unresolved external symbol
_memcpy
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol _memcpy
mtest1.obj : error LNK2019: unresolved external symbol
_memmove referenced in function "public: static char *
__cdecl std::char_trait s<char>::move(c har *,char const
*,unsigned int)" (?move@?
$char_traits@D@ std@@SAPADPADPB DI@Z)
stltest.obj : error LNK2001: unresolved external symbol
_memmove
libcpmtd.lib(st ring.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>::dealloca te(char
*,unsigned int)" (?deallocate@?
$allocator@D@st d@@QAEXPADI@Z)
stltest.obj : error LNK2001: unresolved external
symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z)
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z)
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol "void __cdecl operator delete(void *)" (??
3@YAXPAX@Z)
mtest1.obj : error LNK2019: unresolved external symbol
___CxxFrameHand ler referenced in function __ehhandler$?
_Copy@?$basic_s tring@DU?$char_ traits@D@std@@V ?
$allocator@D@2@ @std@@IAEXII@Z
stltest.obj : error LNK2019: unresolved external symbol
___CxxFrameHand ler referenced in function $L12690
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol ___CxxFrameHand ler
mtest1.obj : error LNK2019: unresolved external symbol
__except_list referenced in function "protected: void
__thiscall std::basic_stri ng<char,struct
std::char_trait s<char>,class std::allocator< char> >::_Copy
(unsigned int,unsigned int)" (?_Copy@?$basic _string@DU?
$char_traits@D@ std@@V?$allocat or@D@2@@std@@IA EXII@Z)
stltest.obj : error LNK2001: unresolved external symbol
__except_list
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol __except_list
mtest1.obj : error LNK2019: unresolved external symbol
__CxxThrowExcep tion@8 referenced in function $L12724
stltest.obj : error LNK2001: unresolved external symbol
__CxxThrowExcep tion@8
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol __CxxThrowExcep tion@8
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol __CxxThrowExcep tion@8
mtest1.obj : error LNK2019: unresolved external symbol
_free referenced in function "void __cdecl
std::_DebugHeap Delete<void>(vo id *)" (??
$_DebugHeapDele te@X@std@@YAXPA X@Z)
stltest.obj : error LNK2001: unresolved external symbol
_free
libcpmtd.lib(xl ock.obj) : error LNK2019: unresolved
external symbol _atexit referenced in function _$E1
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol _atexit
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol "public: __thiscall exception::exce ption
(class exception const &)" (??0exception@@ QAE@ABV0@@Z)
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol "public: __thiscall exception::exce ption
(class exception const &)" (??0exception@@ QAE@ABV0@@Z)
libcpmtd.lib(st ring.obj) : error LNK2001: unresolved
external symbol "const type_info::`vft able'" (??
_7type_info@@6B @)
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol "const type_info::`vft able'" (??
_7type_info@@6B @)
libcpmtd.lib(st ring.obj) : error LNK2019: unresolved
external symbol "public: virtual __thiscall
exception::~exc eption(void)" (??1exception@@ UAE@XZ)
referenced in function $L12220
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol "public: virtual __thiscall
exception::~exc eption(void)" (??1exception@@ UAE@XZ)
libcpmtd.lib(st ring.obj) : error LNK2019: unresolved
external symbol "public: __thiscall exception::exce ption
(void)" (??0exception@@ QAE@XZ) referenced in
function "public: __thiscall std::logic_erro r::logic_error
(class std::basic_stri ng<char,struct
std::char_trait s<char>,class std::allocator< char> > const
&)" (??0logic_error @std@@QAE@ABV?$ basic_string@DU ?
$char_traits@D@ std@@V?$allocat or@D@2@@1@@Z)
libcpmtd.lib(st ring.obj) : error LNK2019: unresolved
external symbol _strlen referenced in function "public:
static unsigned int __cdecl std::char_trait s<char>::lengt h
(char const *)" (?length@?$char _traits@D@std@@ SAIPBD@Z)
libcpmtd.lib(xd ebug.obj) : error LNK2019: unresolved
external symbol __malloc_dbg referenced in function "void
* __cdecl operator new(unsigned int,struct
std::_DebugHeap Tag_t const &,char *,int)" (??
2@YAPAXIABU_Deb ugHeapTag_t@std @@PADH@Z)
libcpmtd.lib(xd ebug.obj) : error LNK2019: unresolved
external symbol __free_dbg referenced in function "void
__cdecl operator delete(void *,struct std::_DebugHeap Tag_t
const &,char *,int)" (??
3@YAXPAXABU_Deb ugHeapTag_t@std @@PADH@Z)
libcpmtd.lib(ne wop.obj) : error LNK2019: unresolved
external symbol __callnewh referenced in function "void *
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
libcpmtd.lib(ne wop.obj) : error LNK2019: unresolved
external symbol _malloc referenced in function "void *
__cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
libcpmtd.lib(no memory.obj) : error LNK2001: unresolved
external symbol "public: virtual char const * __thiscall
exception::what (void)const " (?what@exceptio n@@UBEPBDXZ)
libcpmtd.lib(no memory.obj) : error LNK2019: unresolved
external symbol "public: __thiscall exception::exce ption
(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_u sed
---
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 thefollowing error message:
Linking...
LINK : error LNK2020: unresolved token (0A000005)
_CrtDbgReportLINK : 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)
_CxxThrowExcept ionLINK : 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.__ctorLINK : error LNK2020: unresolved token (0A0000A6)
exception.__dto rLINK : error LNK2020: unresolved token (0A0000A7)
exception.__cto rLINK : error LNK2020: unresolved token (0A0000A8)
exception.__cto rLINK : fatal error LNK1120: 16 unresolved externals
Note that "Ignore All Default Libraries" is set to "No"
and that the codebuilds fine when using the unmanaged C++ compiler and
targetting nativecode. If I use the DLL version of the library, I get a
slightly differentlist of errors.
What should I do to get this to build correctly?
Thanks,
Aaron Queenan.
.