• Advertisement
Sign in to follow this  

[.net] Link error with managed class

This topic is 4869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm new to managed c++ so this is probably an easy fix but I can't seem to figure it out. And I can't find anything useful on google. I have a library that I want to wrap in managed c++ but I get this error when I include my library header: Linking... LINK : error LNK2020: unresolved token (0A000006) _CxxThrowException LINK : error LNK2020: unresolved token (0A000014) delete LINK : fatal error LNK1120: 2 unresolved externals Now I creating this as a .NET class library project. I believe this is the right project as I only want to use the class in other .NET languages including managed C++. Since that didn't work, I tried importing my library using a .NET console project instead and for some reason it worked. Don't know why that is? I then repeated the process for both but came to the same conclusion. Here's my .NET class library project (doesn't compile):

//////////////////////////// Wrapper.cpp file
#include "stdafx.h"
#include "Wrapper.h"



//////////////////////////// Wrapper.h file
#pragma once
#using <mscorlib.dll>
#include "MyLib.h"
#pragma comment(lib, "MyLib.lib")

using namespace System;

namespace Wrapper
{
    public __gc class Class1
    {
    // TODO: Add your methods for this class here.
    };
}






Here's my .NET console project (compiles fine):
// This is the main project file for VC++ application project 
// generated using an Application Wizard.

#include "stdafx.h"
#using <mscorlib.dll>

#include "MyLib.h"
#pragma comment(lib, "MyLib.lib")

using namespace System;

__gc class ManagedWrapper
{
public:

     MyLib* pLibrary;

    public:

     ManagedWrapper()
     {
          pLibrary = new MyLib();
       }
     ~ManagedWrapper()
     {
          delete pLibrary ;
     }
};

int _tmain()
{
     ManagedWrapper* plibrary = new ManagedWrapper();
     return 0;
}






Share this post


Link to post
Share on other sites
Advertisement
Well I managed to get it to compile but I didn't entirely fix the problem yet. It appears that managed C++ doesn't like the Standard Template Library that I'm using in my header file.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement