读书人

动态库声称出现异常

发布时间: 2013-08-14 14:27:55 作者: rapoo

动态库声称出现错误
写一个动态库出现问题了
头文件如下:
#include <iostream>
#include <vector>
#include <list>
#include <string.h>
using namespace std;

#define DLLTEST_API __declspec(dllexport)


// This class is exported from the dlltest.dll

class DLLTEST_API DepTreeEntity
{
friend ostream & operator << ( ostream & os , DepTreeEntity temp );
public:
//成员变量
int depId;
char depName[80];
//string depName;
int parentId;
char fullPath[80];
int nodeOrder;
int onlineChannelCount;
int offlineChannelCount;

//成员函数
void PrintId(void);
void PrintdepName(void);
void PrintparentId(void);
void PrintfullPath(void);
void PrintnodeOrder(void);
void PrintonlineChannelCount(void);
void PrintofflineChannelCount(void);

DepTreeEntity();
DepTreeEntity(DepTreeEntity* stu1);
DepTreeEntity(int depId,const char* depName,int parentId,const char* fullPath,
int nodeOrder,int onlineChannelCount,int offlineChannelCount);
friend ostream & operator << ( ostream & os , DepTreeEntity temp );

};

DLLTEST_API void Print(list<DepTreeEntity> *L/*, int Option*/);




函数实现的cpp如下:
#include "stdafx.h"
#include "dlltest.h"



DepTreeEntity::DepTreeEntity(DepTreeEntity* stu1)
{
depId = stu1->depId;
memcpy(depName,"TREE_depName",strlen("TREE_depName")+1);
parentId = stu1->parentId;
memcpy(fullPath,"TREE_fullPath",strlen("TREE_fullPath")+1);
nodeOrder = stu1->nodeOrder;
onlineChannelCount = stu1->onlineChannelCount;
offlineChannelCount = stu1->offlineChannelCount;
//memcpy(birthday,"stu_birthday",strlen("stu_birthday")+1);
}
DepTreeEntity::DepTreeEntity(int depId,const char* depName,int parentId, const char* fullPath,
int nodeOrder,int onlineChannelCount,int offlineChannelCount)
{
this->depId = depId;
memcpy(this->depName,depName,strlen(depName)+1);
this->parentId = parentId;
memcpy(this->fullPath,fullPath,strlen(fullPath)+1);
this->nodeOrder = nodeOrder;
this->onlineChannelCount=onlineChannelCount;
this->offlineChannelCount=offlineChannelCount;
//memcpy(this->birthday,birthday,strlen(birthday)+1);


}
ostream & operator << ( ostream & os , DepTreeEntity temp )
{
os << "depId: " << temp.depId << endl
<< "depName: " << temp.depName << endl
<< "parentId: " << temp.parentId << endl
<< "fullPath: "<< temp.fullPath << endl
<< "nodeOrder: "<< temp.nodeOrder << endl
<< "onlineChannelCount: "<< temp.onlineChannelCount << endl
<< "offlineChannelCount: "<< temp.offlineChannelCount << endl;
return os;
}
void DepTreeEntity::PrintId(void)
{
cout << depId << endl;
}
void DepTreeEntity::PrintdepName(void)
{
cout << depName << endl;
}
void DepTreeEntity::PrintparentId(void)
{
cout << parentId << endl;
}
void DepTreeEntity::PrintfullPath(void)
{
cout << fullPath << endl;
}
void DepTreeEntity::PrintnodeOrder(void)
{
cout << nodeOrder << endl;
}
void DepTreeEntity::PrintonlineChannelCount(void)
{
cout << onlineChannelCount << endl;
}
void DepTreeEntity::PrintofflineChannelCount(void)
{
cout << offlineChannelCount << endl;
}


生成解决方案时候出现了4个问题
error LNK2019: 无法解析的外部符号 "void __cdecl Print(class std::list<class DepTreeEntity,class std::allocator<class DepTreeEntity> > *)" (?Print@@YAXPAV?$list@VDepTreeEntity@@V?$allocator@VDepTreeEntity@@@std@@@std@@@Z),该符号在函数 _main 中被引用


error LNK2019: 无法解析的外部符号 "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class DepTreeEntity)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@VDepTreeEntity@@@Z),该符号在函数 _main 中被引用
2>dllcall.obj :

error LNK2019: 无法解析的外部符号 "public: __thiscall DepTreeEntity::DepTreeEntity(int,char const *,int,char const *,int,int,int)" (??0DepTreeEntity@@QAE@HPBDH0HHH@Z),该符号在函数 _main 中被引用
2>dllcall.obj :

error LNK2019: 无法解析的外部符号 "public: __thiscall DepTreeEntity::DepTreeEntity(void)" (??0DepTreeEntity@@QAE@XZ),该符号在函数 _main 中被引用




求大神解答
[解决办法]
计算机组成原理→DOS命令→汇编语言→C语言(不包括C++)、代码书写规范→数据结构、编译原理、操作系统→计算机网络、数据库原理、正则表达式→其它语言(包括C++)、架构……

对学习编程者的忠告:
眼过千遍不如手过一遍!
书看千行不如手敲一行!
手敲千行不如单步一行!
单步源代码千行不如单步对应汇编一行!

单步类的实例“构造”或“复制”或“作为函数参数”或“作为函数返回值返回”或“参加各种运算”或“退出作用域”的语句对应的汇编代码几步后,就会来到该类的“构造函数”或“复制构造函数”或“运算符重载”或“析构函数”对应的C/C++源代码处。

VC调试时按Alt+8、Alt+7、Alt+6和Alt+5,打开汇编窗口、堆栈窗口、内存窗口和寄存器窗口看每句C对应的汇编、单步执行并观察相应堆栈、内存和寄存器变化,这样过一遍不就啥都明白了吗。
对VC来说,所谓‘调试时’就是编译连接通过以后,按F10或F11键单步执行一步以后的时候,或者在某行按F9设了断点后按F5执行停在该断点处的时候。
[解决办法]
将错误信息中出现的标识符放在google里面搜一下,看其在哪个.lib中,然后在本地硬盘上搜索该.lib,如果没有,在网上搜索相关库或模块下载安装,然后将其所在目录填写到“附加依赖库所在目录”中,将其名字添加到“附加依赖库”中,重新连接。

VC6:
工程、设置、C/C++、分类:Preprocessor、附加包含路径:填写附加头文件所在目录 逗号间隔多项
工程、设置、Link、分类:Input、附加库路径:填写附加依赖库所在目录 分号间隔多项
工程、设置、Link、分类:Input、对象/库模块:填写附加依赖库的名字.lib 空格间隔多项
VS20xx:
项目、属性、C/C++、附加包含目录:填写附加头文件所在目录 分号间隔多项
项目、属性、链接器、常规、附加库目录:填写附加依赖库所在目录 分号间隔多项
项目、属性、链接器、输入、附加依赖项:填写附加依赖库的名字.lib 空格或分号间隔多项

[解决办法]
DLLTEST_API 这个宏 必须有两个定义
1) 这个用于 实现动态库
#define DLLTEST_API __declspec(dllexport)
2)这个用于引用动态库
#define DLLTEST_API __declspec(dllimport)

这个可通过定义,另一个宏实现。
具体可以看,MFC自动生成的动态库程序。

读书人网 >C++

热点推荐