0
votes

I'm trying to wrap a unmanaged C++ DLL with managed C++ and I keep getting linking errors.

even though I include my library.lib in the project and include the correct header file.

This is the managed class:

#pragma once
#include "..\Terminal\Terminal.h"
public ref class ManagedTerminal
{
    private:
Terminal * m_unTerminal;
public:

ManagedTerminal(void)
{
    m_unTerminal = new Terminal();
}
};

and this is the unmanaged class:

#include "..\Core1.h"
#include "..\Core2.h"

 __declspec(dllexport) class Terminal
{
private:
CoreObj m_core;

public:
Terminal();
void Init(char* path, char* filename);    
void Start();
void Stop();
void Run();
Array<Report> GetSnapshot();
~Terminal(void);
};

and the errors I get are:

Error 5 error LNK2028: unresolved token (0A0000B3) "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$FQAE@XZ) referenced in function "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper

Error 6 error LNK2019: unresolved external symbol "public: __thiscall Terminal::Terminal(void)" (??0Terminal@@$$FQAE@XZ) referenced in function "public: __clrcall ManagedTerminal::ManagedTerminal(void)" (??0ManagedTerminal@@$$FQ$AAM@XZ) ManagedTerminal.obj TerminalWrapper

can anybody tell me what's wrong? thanks :)

1
Does the unmanaged C++ dll use boost::thread? - Armen Tsirunyan
possible duplicate of [I get LNK2028 when trying to wrap native c++ class using managed c++ ](stackoverflow.com/questions/721387/…) - Steve Townsend
Could you try to make possibly small example that reproduces the problem? - Vlad
Post the exact error message, the symbol name gives a lot of clues. And a snippet that shows the declaration of course. - Hans Passant

1 Answers

1
votes

You have to match all of the build settings -- specifically the calling conventions (CDECL vs. STDCALL) -- in order to have a successful link.

Since .NET 2.0, you have also had to link to the c-runtime dynamically, so make sure that both the .dll and the managed C++ project do this.

Basically, go into the properties dialog for both projects and make sure that things that affect the call are the same.