views:

58

answers:

1

Hi! 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 :)

A: 

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.

Lou Franco
I've changed the calling convention of the managed project to "__cdecl" (as in the unmanaged project) but now I get the error:Error 30 fatal error LNK1104: cannot open file '..\Debug\Terminal.lib' even though it is there.
Idov
Download procmon.exe from Microsoft and set a filter for the path containing Terminal.lib and make sure it's using the PATH you think it is. Also, if it fails to open, procmon will tell you why.
Lou Franco