problems using STL when building managed C++ class libraries

V

vector

I am trying with little success to create a .NET class library using
Visual C++ .NET 2003. My project will use STL. I can add to my
solution without trouble a C# test application which calls into my C++
library.

When I merely add the line "#include <vector>" to my main DLL file in
the C++ project, 25 build errors appear. If I add a line
"std::vector<int> integers;" to a function in the project, even
without using that vector, the error count is reduced to 3.

I can use STL vectors in managed C++ console application projects
without these difficulties. I suspect a project setting to be wrong,
but can't seem to isolate it.

Can someone please offer advice on how to correct these problems?


--- the 3 errors ---

error LNK2020: unresolved token (0A00000B) exception.__ctor
error LNK2020: unresolved token (0A00000C) ??_7type_info@@6B@
error LNK2020: unresolved token (0A000016) exception.__dtor
fatal error LNK1120: 3 unresolved externals

--- the 25 errors ---

error LNK2001: unresolved external symbol "const type_info::`vftable'"
(??_7type_info@@6B@)
error LNK2001: unresolved external symbol "const type_info::`vftable'"
(??_7type_info@@6B@)
error LNK2001: unresolved external symbol "int __cdecl
__CxxDetectRethrow(void *)" (?__CxxDetectRethrow@@$$J0YAHPAX@Z)
error LNK2001: unresolved external symbol "int __cdecl
__CxxExceptionFilter(void *,void *,int,void *)"
(?__CxxExceptionFilter@@$$J0YAHPAX0H0@Z)
error LNK2001: unresolved external symbol "int __cdecl
__CxxQueryExceptionSize(void)" (?__CxxQueryExceptionSize@@$$J0YAHXZ)
error LNK2001: unresolved external symbol "int __cdecl
__CxxRegisterExceptionObject(void *,void *)"
(?__CxxRegisterExceptionObject@@$$J0YAHPAX0@Z)
error LNK2001: unresolved external symbol "public: __thiscall
exception::exception(class exception const &)"
(??0exception@@QAE@ABV0@@Z)
error LNK2001: unresolved external symbol "public: __thiscall
exception::exception(class exception const &)"
(??0exception@@QAE@ABV0@@Z)
error LNK2001: unresolved external symbol "public: virtual __thiscall
exception::~exception(void)" (??1exception@@UAE@XZ)
error LNK2001: unresolved external symbol "public: virtual char const
* __thiscall exception::what(void)const " (?what@exception@@UBEPBDXZ)
error LNK2001: unresolved external symbol "void * __cdecl memcpy(void
*,void const *,unsigned int)" (?memcpy@@$$J0YAPAXPAXPBXI@Z)
error LNK2001: unresolved external symbol "void * __cdecl memmove(void
*,void const *,unsigned int)" (?memmove@@$$J0YAPAXPAXPBXI@Z)
error LNK2001: unresolved external symbol "void __cdecl
__CxxUnregisterExceptionObject(void *,int)"
(?__CxxUnregisterExceptionObject@@$$J0YAXPAXH@Z)
error LNK2001: unresolved external symbol "void __cdecl operator
delete(void *)" (??3@$$FYAXPAX@Z)
error LNK2001: unresolved external symbol "void __stdcall
_CxxThrowException(void *,struct _s__ThrowInfo const *)"
(?_CxxThrowException@@$$J18YGXPAXPBU_s__ThrowInfo@@@Z)
error LNK2001: unresolved external symbol __load_config_used
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)
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)
error LNK2019: unresolved external symbol "public: virtual __thiscall
exception::~exception(void)" (??1exception@@UAE@XZ) referenced in
function $L12220
error LNK2019: unresolved external symbol ___CxxFrameHandler
referenced in function __ehhandler$?_Xlen@_String_base@std@@QBEXXZ
error LNK2019: unresolved external symbol __callnewh referenced in
function "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
error LNK2019: unresolved external symbol __except_list referenced in
function "public: void __thiscall std::_String_base::_Xlen(void)const
" (?_Xlen@_String_base@std@@QBEXXZ)
error LNK2019: unresolved external symbol _atexit referenced in
function "void __cdecl std::_Nomemory(void)" (?_Nomemory@std@@YAXXZ)
error LNK2019: unresolved external symbol _malloc referenced in
function "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
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)
 
J

Jacobo Rodriguez

vector said:
I am trying with little success to create a .NET class library using
Visual C++ .NET 2003. My project will use STL. I can add to my
solution without trouble a C# test application which calls into my C++
library.

When I merely add the line "#include <vector>" to my main DLL file in
the C++ project, 25 build errors appear. If I add a line
"std::vector<int> integers;" to a function in the project, even
without using that vector, the error count is reduced to 3.

I can use STL vectors in managed C++ console application projects
without these difficulties. I suspect a project setting to be wrong,
but can't seem to isolate it.

Can someone please offer advice on how to correct these problems?


--- the 3 errors ---

error LNK2020: unresolved token (0A00000B) exception.__ctor
error LNK2020: unresolved token (0A00000C) ??_7type_info@@6B@
error LNK2020: unresolved token (0A000016) exception.__dtor
fatal error LNK1120: 3 unresolved externals

--- the 25 errors ---

error LNK2001: unresolved external symbol "const type_info::`vftable'"
(??_7type_info@@6B@)
error LNK2001: unresolved external symbol "const type_info::`vftable'"
(??_7type_info@@6B@)
error LNK2001: unresolved external symbol "int __cdecl
__CxxDetectRethrow(void *)" (?__CxxDetectRethrow@@$$J0YAHPAX@Z)
error LNK2001: unresolved external symbol "int __cdecl
__CxxExceptionFilter(void *,void *,int,void *)"
(?__CxxExceptionFilter@@$$J0YAHPAX0H0@Z)
error LNK2001: unresolved external symbol "int __cdecl
__CxxQueryExceptionSize(void)" (?__CxxQueryExceptionSize@@$$J0YAHXZ)
error LNK2001: unresolved external symbol "int __cdecl
__CxxRegisterExceptionObject(void *,void *)"
(?__CxxRegisterExceptionObject@@$$J0YAHPAX0@Z)
error LNK2001: unresolved external symbol "public: __thiscall
exception::exception(class exception const &)"
(??0exception@@QAE@ABV0@@Z)
error LNK2001: unresolved external symbol "public: __thiscall
exception::exception(class exception const &)"
(??0exception@@QAE@ABV0@@Z)
error LNK2001: unresolved external symbol "public: virtual __thiscall
exception::~exception(void)" (??1exception@@UAE@XZ)
error LNK2001: unresolved external symbol "public: virtual char const
* __thiscall exception::what(void)const " (?what@exception@@UBEPBDXZ)
error LNK2001: unresolved external symbol "void * __cdecl memcpy(void
*,void const *,unsigned int)" (?memcpy@@$$J0YAPAXPAXPBXI@Z)
error LNK2001: unresolved external symbol "void * __cdecl memmove(void
*,void const *,unsigned int)" (?memmove@@$$J0YAPAXPAXPBXI@Z)
error LNK2001: unresolved external symbol "void __cdecl
__CxxUnregisterExceptionObject(void *,int)"
(?__CxxUnregisterExceptionObject@@$$J0YAXPAXH@Z)
error LNK2001: unresolved external symbol "void __cdecl operator
delete(void *)" (??3@$$FYAXPAX@Z)
error LNK2001: unresolved external symbol "void __stdcall
_CxxThrowException(void *,struct _s__ThrowInfo const *)"
(?_CxxThrowException@@$$J18YGXPAXPBU_s__ThrowInfo@@@Z)
error LNK2001: unresolved external symbol __load_config_used
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)
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)
error LNK2019: unresolved external symbol "public: virtual __thiscall
exception::~exception(void)" (??1exception@@UAE@XZ) referenced in
function $L12220
error LNK2019: unresolved external symbol ___CxxFrameHandler
referenced in function __ehhandler$?_Xlen@_String_base@std@@QBEXXZ
error LNK2019: unresolved external symbol __callnewh referenced in
function "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
error LNK2019: unresolved external symbol __except_list referenced in
function "public: void __thiscall std::_String_base::_Xlen(void)const
" (?_Xlen@_String_base@std@@QBEXXZ)
error LNK2019: unresolved external symbol _atexit referenced in
function "void __cdecl std::_Nomemory(void)" (?_Nomemory@std@@YAXXZ)
error LNK2019: unresolved external symbol _malloc referenced in
function "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)
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)

Remove the /ZI command line option in the linker options

--
Jacobo Rodríguez Villar

Proyectos en desarrollo:

http://www.typhoonlabs.com
 
V

vector

Jacobo Rodriguez said:
Remove the /ZI command line option in the linker options

Regrettably, this did not solve my problems. Further, this switch is
to generate debug information, which I typically do not do for release
builds. My class library does not build successfully in either
Release or Debug configuration.

This issue continues to be an outstanding issue for me. Is there
nothing else I can try?
 
A

andrew

yes. include msvcrt.lib helps linker to find delete and free.

but the following errors appear instead:

Linking...
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(_tolower.obj) : error LNK2001: unresolved external symbol __malloc_dbg
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)

which other libs need to be included ?
 
B

Bob Milton

Andrew,
You are running a debug link, so you need msvcrtd.lib. The extra d is
for debug, and will take care of your missing references.
Bob Milton
 
D

DotNetJunkies User

Thanks.....msvcrtd.lib did the trick for my debug build too....I wonder what msvcrtd.lib stands for.
 
G

Guest

----- DotNetJunkies User wrote: ----

Thanks.....msvcrtd.lib did the trick for my debug build too....I wonder what msvcrtd.lib stands for


MicroSoft Visual C RunTime Debug Library, most likely.
 
D

DotNetJunkies User

Thank you for posting this message and thanks to the rest of you for providing suggestions. I had the exact same problem! Adding msvcrt.lib got my project to build. Hope you eventually got yours building.

Jennifer MacKay
 
J

jamiec

I hit a similar problem. I create a .NET Class Library called foofoo. It compiles and links fine.

Then I add
#include <vector>
to foofoo.cpp

It compiles fine, but when it links it gives many errors.

Does anyone have a workaround? I tried the suggestions on this page, but did not have any luck.


------ Build started: Project: foofoo, Configuration: Debug Win32 ------

Compiling...
foofoo.cpp
Linking...
foofoo.obj : error LNK2001: unresolved external symbol "void * __cdecl memcpy(void *,void const *,unsigned int)" (?memcpy@@$$J0YAPAXPAXPBXI@Z)
foofoo.obj : error LNK2001: unresolved external symbol "void * __cdecl memmove(void *,void const *,unsigned int)" (?memmove@@$$J0YAPAXPAXPBXI@Z)
foofoo.obj : error LNK2001: unresolved external symbol "void __cdecl operator delete(void *)" (??3@$$FYAXPAX@Z)
foofoo.obj : error LNK2001: unresolved external symbol "void __cdecl __CxxUnregisterExceptionObject(void *,int)" (?__CxxUnregisterExceptionObject@@$$J0YAXPAXH@Z)
foofoo.obj : error LNK2001: unresolved external symbol "void __stdcall _CxxThrowException(void *,struct _s__ThrowInfo const *)" (?_CxxThrowException@@$$J18YGXPAXPBU_s__ThrowInfo@@@Z)
foofoo.obj : error LNK2001: unresolved external symbol "int __cdecl __CxxRegisterExceptionObject(void *,void *)" (?__CxxRegisterExceptionObject@@$$J0YAHPAX0@Z)
foofoo.obj : error LNK2001: unresolved external symbol "int __cdecl __CxxQueryExceptionSize(void)" (?__CxxQueryExceptionSize@@$$J0YAHXZ)
foofoo.obj : error LNK2001: unresolved external symbol "int __cdecl __CxxDetectRethrow(void *)" (?__CxxDetectRethrow@@$$J0YAHPAX@Z)
foofoo.obj : error LNK2001: unresolved external symbol "int __cdecl __CxxExceptionFilter(void *,void *,int,void *)" (?__CxxExceptionFilter@@$$J0YAHPAX0H0@Z)
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 ___CxxFrameHandler referenced in function __ehhandler$?_Xlen@_String_base@std@@QBEXXZ
libcpmtd.lib(string.obj) : error LNK2019: unresolved external symbol __except_list referenced in function "public: void __thiscall std::_String_base::_Xlen(void)const " (?_Xlen@_String_base@std@@QBEXXZ)
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(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 LNK2019: unresolved external symbol _atexit referenced in function "void __cdecl std::_Nomemory(void)" (?_Nomemory@std@@YAXXZ)
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
C:\Documents and Settings\Jamie Cho\Desktop\foofoo\Debug\foofoo.dll : fatal error LNK1120: 22 unresolved externals

Build log was saved at "file://c:\Documents and Settings\Jamie Cho\Desktop\foofoo\foofoo\Debug\BuildLog.htm"
foofoo - 26 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 0 succeeded, 1 failed, 0 skipped
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top