[Dev-C++] Couldn`t link MinGW DLL to MSVC program
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Dmitry S. <si...@si...> - 2005-03-27 09:40:28
|
Hello dev-cpp-users.
I have the following source files to build DLL with Dev-Cpp
// dll.h
#ifndef _DLL_H_
#define _DLL_H_
#if BUILDING_DLL
# define DLLIMPORT __declspec (dllexport)
#else /* Not BUILDING_DLL */
# define DLLIMPORT __declspec (dllimport)
#endif /* Not BUILDING_DLL */
class DLLIMPORT MyClass
{
public:
MyClass();
virtual ~MyClass(void);
};
#endif /* _DLL_H_ */
// dllmain.cpp
#include "dll.h"
#include <windows.h>
MyClass::MyClass()
{
MessageBox( NULL, "MyClass construccted!!!", "test", 0 );
}
MyClass::~MyClass()
{
}
BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
DWORD reason /* Reason this function is being called. */ ,
LPVOID reserved /* Not used. */ )
{
switch (reason)
{
case DLL_PROCESS_ATTACH:
break;
case DLL_PROCESS_DETACH:
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
}
/* Returns TRUE on success, FALSE on failure */
return TRUE;
}
This is standard DLL project of Dev-Cpp with MessageBox function in
MyClass constructor
I build DLL with Dev-Cpp and then build .LIB file by LIB.exe from the
MSVC installation.
lib.exe /machine:i386 /def:libhellodll.def
Then I create the following code in MSVC
// testdll.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "dll.h"
int _tmain(int argc, _TCHAR* argv[])
{
MyClass hello;
return 0;
}
I also add libhellodll.lib to MSVC project
But when my testdll is linking I got the following errors
testdll2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall MyClass::MyClass(void)" (__imp_??0MyClass@@QAE@XZ) referenced in function _main
testdll2 error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall MyClass::~MyClass(void)" (__imp_??1MyClass@@UAE@XZ) referenced in function _main
testdll2 fatal error LNK1120: 2 unresolved externals
Then I tried to use dlltool from MinGW
dlltool.exe -d libhellodll.def --dllname hellodll.dll --output-lib libhellodll.lib
But I`ve got the same error
I also tried to use dlltool.exe with -U and -k flags, I`ve got the
same errors :(
Can anybody help me?
Excuse me for my poor english
--
Dmitry
|