Question: native new linkage error

O

| ov

Hi,
Need some help here.
I have a .NET class library in C++ (with CLR).
In this project I have a class with the __nogc keyword. When I use the
new operator within this class's code I receive:
error LNK2001: unresolved external symbol "void * __cdecl operator
new(unsigned int)" (??2@$$FYAPAXI@Z)

I think I should be able to use unmanaged runtime's new operator from
a .NET project, but I must be doing something wrong. Any ideas ?

BTW: I've referenced mscorlib

Thanks,
 
C

Carl Daniel [VC++ MVP]

| ov said:
Hi,
Need some help here.
I have a .NET class library in C++ (with CLR).
In this project I have a class with the __nogc keyword. When I use the
new operator within this class's code I receive:
error LNK2001: unresolved external symbol "void * __cdecl operator
new(unsigned int)" (??2@$$FYAPAXI@Z)

I think I should be able to use unmanaged runtime's new operator from
a .NET project, but I must be doing something wrong. Any ideas ?

BTW: I've referenced mscorlib

Make you're linking against a version of the CRT. IIRC, for managed apps
you need to use the DLL runtime library (MSVCR70.DLL). You may need to
explicitly add msvcrt.lib to the linker settings.

-cd
 
O

| ov

Hi, Carl.
I've added msvcrt to both debug and release builds and now everything
works fine. Thanks you.

However, I haven't understood what you meant by: "IIRC, for managed
apps you need to use the DLL runtime library (MSVCR70.DLL)" ?

Thanks, again...
 
C

Carl Daniel [VC++ MVP]

| ov said:
Hi, Carl.
I've added msvcrt to both debug and release builds and now everything
works fine. Thanks you.

However, I haven't understood what you meant by: "IIRC, for managed
apps you need to use the DLL runtime library (MSVCR70.DLL)" ?

When you add msvcrt.lib to the link, you're using the DLL runtime library -
msvcrt.lib is an "import library" and simply serves to make associations
between your EXE and the DLL runtime library, which is named MSVCR71.DLL if
you're using VS.NET 2003. (MSVCR70.DLL if you're using VS.NET 2002).

-cd
 

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