Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / July 2004

Tip: Looking for answers? Try searching our database.

problems using STL when building managed C++ class libraries

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vector - 29 Mar 2004 01:11 GMT
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)
Jacobo Rodriguez - 29 Mar 2004 11:08 GMT
> 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
[quoted text clipped - 86 lines]
> std::char_traits<char>::length(char const *)"
> (?length@?$char_traits@D@std@@SAIPBD@Z)

Remove the /ZI command line option in the linker options

Signature

Jacobo Rodríguez Villar

Proyectos en desarrollo:

http://www.typhoonlabs.com

vector - 01 Apr 2004 19:12 GMT
> 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?
cschettle - 02 Apr 2004 23:58 GMT
I think you need to link with msvcrt.lib
andrew - 18 Apr 2004 18:50 GMT
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 ?

---
Bob Milton - 18 Apr 2004 19:40 GMT
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

> yes. include msvcrt.lib helps linker to find delete and free.
>
[quoted text clipped - 18 lines]
>  Our newsgroup
> engine supports Post Alerts, Ratings, and Searching.
DotNetJunkies User - 04 May 2004 23:00 GMT
Thanks.....msvcrtd.lib did the trick for my debug build too....I wonder what msvcrtd.lib stands for.

---
Michael Maddox - 07 May 2004 20:51 GMT
----- 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.
jamiec@-NOSPAM-mac.com - 15 Jul 2004 21:08 GMT
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

---
DotNetJunkies User - 21 May 2004 20:46 GMT
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

---

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.