关于DEVCPP 下 做DLL 的简单问题!!
我是用DEVCPP 做的。有三个文件dll.h,dll.cpp 这两个文件实现了一个DLL,main.cpp调用了这个DLL,不知道错在哪里,望大虾指教!!
dll.h
#ifndef _DLL_H_
#define _DLL_H_
__declspec (dllexport) int __cdecl add (int a,int b);
#endif /* _DLL_H_ */
dll.cpp
/* Replace "dll.h" with the name of your header */
#include "dll.h"
#include <windows.h>
__declspec (dllexport) int __cdecl add (int a,int b)
{
return (a+b);
}
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;
}
main.cpp
#include <iostream>
#include <windows.h>
extern "C" __declspec(dllimport) int __cdecl add (int a,int b);
int main()
{
std::cout << add(5,10) << std::endl;
system("pause");
}
提示错误是 [Linker error] undefined reference to `_imp__add'