error LNK2001: unresolved external symbol "void * __cdecl operator new(unsigned int)"


  • Hi,

    I'm rather new to developing in .NET. I'm  trying to create a managed extensions wrapper around unmanaged C++ code.

    The compilation works fine, but I'm getting the link error specified in the title, for "new" and "delete".

    From searching the web I found that adding "msvcrt.lib" to the input libraties solves the problem.

    My question:
    Is there another way other than manually adding this library? Is there an option in the project's property page?


    Sunday, December 25, 2005 1:18 PM

All replies

  • Hi Osnat:

    You can specify the default CRT via the /MD option for release builds, and /MDd for debug builds.  This will cause the linker to user msvcrt.lib (/MD) or msvcrtd.lib (/MDd) when resolving calls to CRT functions.  At runtime, msvcrt{d}.dll will be loaded.

    Hope This Helps,

    Tuesday, December 27, 2005 10:52 PM
  • Thanks Rick.

    I still have this problem in some scenarios:
    I have the files below. As you can see "ManagedClass.cpp" doesn't contain any code except includes.
    I found that if I exclude "ManagedClass.cpp" from the project the link succeeds, otherwise I am getting the link errors I specified in the original message.
    What am I doing wrong?


    ---------------------------- NativeClass.h -------------------------------------
    #include "stdafx.h"

    class NativeClass {
     bool foo(int i){return true;}

    ---------------------------- ManagedClass.h -------------------------------------
    #pragma once
    #include "stdafx.h"
    #include "NativeClass.h"

    using namespace System::Runtime::InteropServices;
    using namespace System;

    namespace ManagedDLL
     public __gc class ManagedClass
       m_pNativeClass = new NativeClass();

      bool Mfoo(int i)
       return m_pNativeClass->foo(i);

      NativeClass *m_pNativeClass;

    ---------------------------- ManagedClass.cpp -------------------------------------
    #include "stdafx.h"

    #include "ManagedClass.h"



    Wednesday, December 28, 2005 7:23 AM