error C2491: “Add” : 不允许 dllimport 函数 的定义

初学dll,先记录下问题,不求甚解
win2003+vs2003
代码:
include <iostream>
#include "DLLTutorial.h"

#define? DLL_EXPORT
extern "C"
{
DECLDIR int Add(int a, int b)
{
return a+b;
}

DECLDIR void Function(void)
{
std::cout<<"DLL called!"<<std::endl;
}
};

问题:
正在编译...
DLLTutorial.cpp
f:\hbj\112\112\DLLTutorial.cpp(9) : error C2491: “Add” : 不允许 dllimport 函数 的定义
f:\hbj\112\112\DLLTutorial.cpp(14) : error C2491: “Function” : 不允许 dllimport 函数 的定义

解决:
include <iostream>
#include "DLLTutorial.h"

#define? DLL_EXPORT
顺序反了,
应改为:
#define? DLL_EXPORT
#include <iostream>
#include "DLLTutorial.h"

extern "C"
{
DECLDIR int Add(int a, int b)
{
return a+b;
}

DECLDIR void Function(void)
{
std::cout<<"DLL called!"<<std::endl;
}
};



1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets(364,5): warning MSB8004: Output Directory does not end with a trailing slash. This build instance will add the slash as it is required to allow proper evaluation of the Output Directory. 1> 正在创建库 C:\Liuchao\Jiangyin72_5\JGSDK72_5\\bin\plugins\DynTargetPlugin\\DynTargetPlugin.lib 和对象 C:\Liuchao\Jiangyin72_5\JGSDK72_5\\bin\plugins\DynTargetPlugin\\DynTargetPlugin.exp 1>DCTSRHWidget.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class QList<class IGV_DynTargetItem *> __cdecl DynTargetManager::getTargetItem(float,float,float,float,class QString const &)" (__imp_?getTargetItem@DynTargetManager@@QEAA?AV?$QList@PEAVIGV_DynTargetItem@@@@MMMMAEBVQString@@@Z),该符号在函数 "public: void __cdecl DCTSRHWidget::slotRectSearch(class DataEntity *)" (?slotRectSearch@DCTSRHWidget@@QEAAXPEAVDataEntity@@@Z) 中被引用 1>GroupPlayerWidget.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: class QList<class IGV_DynTargetItem *> __cdecl DynTargetManager::getTargetItem(float,float,float,float,class QString const &)" (__imp_?getTargetItem@DynTargetManager@@QEAA?AV?$QList@PEAVIGV_DynTargetItem@@@@MMMMAEBVQString@@@Z) 1>DynTargetPlugin.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: class QList<class IGV_DynTargetItem *> __cdecl DynTargetManager::getTargetItemByName(class QString const &,class QString const &)" (__imp_?getTargetItemByName@DynTargetManager@@QEAA?AV?$QList@PEAVIGV_DynTargetItem@@@@AEBVQString@@0@Z),该符号在函数 "private: void __cdecl DynTargetPlugin::slotDoSearch(class QString)" (?slotDoSearch@DynTargetPlugin@@AEAAXVQString@@@Z) 中被引用 1>NavySystem.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) public: class QList<class IGV_DynTargetItem *> __cdecl DynTargetManager::getTargetItemByName(class QString const &,class QString const &)" (__imp_?getTargetItemByName@DynTargetManager@@QEAA?AV?$QList@PEAVIGV_DynTargetItem@@@@AEBVQString@@0@Z) 1>DynTargetSetting.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl DynTargetManager::getAllTargetItem(class QVector<class IGV_DynTargetItem *> &,class QString const &)" (__imp_?getAllTargetItem@DynTargetManager@@QEAAXAEAV?$QVector@PEAVIGV_DynTargetItem@@@@AEBVQString@@@Z),该符号在函数 "public: void __cdecl DynTargetSetting::slotInitTargetEnd(void)" (?slotInitTargetEnd@DynTargetSetting@@QEAAXXZ) 中被引用 1>WarningAreaDefine.obj : error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: void __cdecl DynTargetManager::getAllTargetItem(class QMap<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class IGV_DynTargetItem *> &,class QString const &)" (__imp_?getAllTargetItem@DynTargetManager@@QEAAXAEAV?$QMap@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEAVIGV_DynTargetItem@@@@AEBVQString@@@Z),该符号在函数 "private: void __cdecl WarningAreaDefine::slotTimeout(void)" (?slotTimeout@WarningAreaDefine@@AEAAXXZ) 中被引用 1>C:\Liuchao\Jiangyin72_5\JGSDK72_5\\bin\plugins\DynTargetPlugin\\DynTargetPlugin.dll : fatal error LNK1120: 4 个无法解析的外部命令
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值