473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

LNK1120 when compiling a C++ library to .NET managed code

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.
Nov 16 '05 #1
4 11321
I've just added MSVCRTD.LIB MSVCPRTD.LIB to the list of libraries, but I now
get the following errors:

Field.obj : error LNK2001: unresolved external symbol "char * __cdecl
strdup(char const *)" (?strdup@@$$J0YAPADPBD@Z)
Platform.obj : error LNK2001: unresolved external symbol "int __cdecl
putenv(char const *)" (?putenv@@$$J0YAHPBD@Z)
Platform.obj : error LNK2001: unresolved external symbol "char * __cdecl
strupr(char *)" (?strupr@@$$J0YAPADPAD@Z)

These are pretty wierd, since they have C++ symbol names even though they
are C functions. Even putting :: in front of the functions where called
doesn't fix the problem.

If I use the static MT libraries the problem goes away, but of course things
like putenv() won't work across two instances of the static libraries, so it
isn't really what I want to do.

What else can I try?

Thanks,
Aaron Queenan.

"Aaron Queenan" <aq*********************@contingent.com.au> wrote in message
news:OW*************@TK2MSFTNGP11.phx.gbl...
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.

Nov 16 '05 #2
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 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) _CxxThrowExceptionLINK : 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.__dtorLINK : error LNK2020: unresolved token (0A0000A7) exception.__ctorLINK : error LNK2020: unresolved token (0A0000A8) exception.__ctorLINK : 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.
.

Nov 16 '05 #3
Tom/Aaron,
I'm having this problem too and it is driving me crazy.
Here's my code:
#pragma once

#include <vector>
#include <string>
using namespace System;

namespace DllProjectwithstring
{
public __gc class Class1
{
};
}

Not too exciting, I was able to finally resolve these linker errors:
LINK : error LNK2020: unresolved token (0A000013) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000023) delete
LINK : fatal error LNK1120: 2 unresolved externals with help from this link:
http://support.microsoft.com/default...b;en-us;140584
It turned out that I was creating a DLL and needed the /MD runtime
library flag instead of /MT which seems to be default (or /MDd and
/MTd if you're in debug mode).

My problem now is I STILL can't get it to link. Here is the latest and
greatest linker error:
DllProjectwithstring error LNK2020: unresolved token (0A000051)
??_7type_info@@6B@
DllProjectwithstring fatal error LNK1120: 1 unresolved externals

If anyone has any idea as to what causes this error I'd really
appreciate it.

Eddie Chaplin

"Tom Reynoldson" <to***************************@complinet.com> wrote in message news:<49****************************@phx.gbl>... 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

---

Nov 16 '05 #4
I was having the same problem. Following links helped me resolve it.

http://msdn.microsoft.com/library/de...ingProblem.asp
http://support.microsoft.com/?id=814472


ed***********@mapinfo.com (Eddie Chaplin) wrote in message news:<24**************************@posting.google. com>...
Tom/Aaron,
I'm having this problem too and it is driving me crazy.
Here's my code:
#pragma once

#include <vector>
#include <string>
using namespace System;

namespace DllProjectwithstring
{
public __gc class Class1
{
};
}

Not too exciting, I was able to finally resolve these linker errors:
LINK : error LNK2020: unresolved token (0A000013) _CxxThrowException
LINK : error LNK2020: unresolved token (0A000023) delete
LINK : fatal error LNK1120: 2 unresolved externals

with help from this link:
http://support.microsoft.com/default...b;en-us;140584
It turned out that I was creating a DLL and needed the /MD runtime
library flag instead of /MT which seems to be default (or /MDd and
/MTd if you're in debug mode).

My problem now is I STILL can't get it to link. Here is the latest and
greatest linker error:
DllProjectwithstring error LNK2020: unresolved token (0A000051)
??_7type_info@@6B@
DllProjectwithstring fatal error LNK1120: 1 unresolved externals

If anyone has any idea as to what causes this error I'd really
appreciate it.

Eddie Chaplin

"Tom Reynoldson" <to***************************@complinet.com> wrote in message news:<49****************************@phx.gbl>...
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

---

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tim | last post by:
I am just creating a hellow world program and it gave me these errors. can you help me out how to resolve this? Thanks, Tim #include <iostream> using namespace std;
5
by: Adam McKee | last post by:
We are using Visual Studio.NET 2003 in our project with .NET framework 1.1. One of our libraries is a mixed-mode dll assembly consisting of one managed C++ library, and several unmanaged C++...
4
by: zlatko | last post by:
Hello. I am new to .net . I have a managed C++ library. It looks like this. // header file namespace cppnetdll { public __gc class Class1 { public: static int foo_int(void);
1
by: Jesse McGrew | last post by:
Hi all, I'm trying to make a plugin DLL for a third-party application, using VC++ .NET 2003. This DLL acts as a bridge between the C++ plugin API of the application, and my actual plugin code...
12
by: Markus Ewald | last post by:
I'm just experimenting around with the VisualC++ 2005 Express Edition Beta and found some strange behavior for which I can't seem to find a workaround. What I've done is set up two static library...
5
by: dovgani | last post by:
I have an unmanaged MFC project. The output is static lib. I would like to compile using /clr option. The native lib size is 64 megs and with /clr and /O1 options is 940 megs. Is it possibly...
1
by: caa | last post by:
I have made a simple text example. I have two projects. First is an unmanaged static lib, containing function F(), which created an object of type A and throws an exception. The second project is...
1
by: Łukasz Z±bik | last post by:
I have project that uses managed c++ where I use c - library, this library contains some variables named generic, during compilation I get error: Error 1 error C2146: syntax error : missing ';'...
3
by: Łukasz | last post by:
I have project that uses managed c++ where I use c - library, this library contains some variables named generic, during compilation I get error: Error 1 error C2146: syntax error : missing ';'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.