DLL初学者问一个小问题:不能定义声明“dllimport”的函数
楼主用的是VS2010
/* 文件名:lib.h */
#ifndef _LIB_H_
#define _LIB_H_ //前面两行指示编译器只包含这个文件一次。
#if defined DLL_EXPORT
#define DECLDIR __declspec(dllexport)
else
#define DECLDIR __declspec(dllimport)
#endif
extern "C" //extern "C"告诉编译器该部分可以在C/C++中使用。
{
DECLDIR int add(int x,int y);
DECLDIR int max(int x,int y);
DECLDIR void fun(void);
}
#endif
/* 文件名:lib.cpp */
#include<iostream>
using namespace std;
#include "lib.h"
#define DLL_EXPORT
extern "C"
{
DECLDIR int add(int x,int y)
{
return (x+y);
}
DECLDIR void fun(void)
{
cout<<"Dll called!"<<endl;
}
}