VerySource

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 637|回复: 7

一个Link2001错误问题:unresolved external symbol "__declspec(dllimport)...

[复制链接]

1

主题

2

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
发表于 2020-3-6 12:00:01 | 显示全部楼层 |阅读模式
我新建了一个Win32 Dynamic-Link Library项目,并添加好最基本的框架代码(test.cpp)。一切都没问题。
我需要在项目中引用到jrtplib库的文件。操作如下:
在project|Settings|Link中添加了jthread.lib jrtplib.lib(两个必须的库);
新建了一个类CRtp专门操作jrtplib相关功能;
在CRtp中添加了最基本的框架代码;  (如果是exe项目,完全没有问题的)
然后在test.cpp中include rtp.h……

rtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: char const * __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::c_str(void)const " (__imp_?c_
str@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEPBDXZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::length(void)const " (__imp_?l
ength@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIXZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static unsigned int const std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::npos" (__imp_?npos@?$basic_
string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@2IB)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: unsigned int __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::find(char,unsigned int)const
" (__imp_?find@?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QBEIDI@Z)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::~basic_string<char,struct std::char_traits
<char>,class std::allocator<char> >(void)" (__imp_??1?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@XZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) bool __cdecl std::operator==(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_st
ring<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??8std@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0@Z)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<
char>,class std::allocator<char> >(char const *,class std::allocator<char> const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@PBDABV?$allocator@D@1@@Z)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::Init::Init(void)" (__imp_??0Init@ios_base@std@@QAE@XZ)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::Init::Init(void)" (__imp_??0Init@ios_base@std@@QAE@XZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::Init::~Init(void)" (__imp_??1Init@ios_base@std@@QAE@XZ)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::ios_base::Init::~Init(void)" (__imp_??1Init@ios_base@std@@QAE@XZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Winit::_Winit(void)" (__imp_??0_Winit@std@@QAE@XZ)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Winit::_Winit(void)" (__imp_??0_Winit@std@@QAE@XZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Winit::~_Winit(void)" (__imp_??1_Winit@std@@QAE@XZ)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::_Winit::~_Winit(void)" (__imp_??1_Winit@std@@QAE@XZ)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) bool __cdecl std::operator<(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class std::basic_str
ing<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??Mstd@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@0@0@Z)
jrtplibd.lib(rtpudpv4transmitter.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >::basic_string<char,struct std::char_traits<
char>,class std::allocator<char> >(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_??0?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@QAE@ABV01@@Z)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::basic_ostream<char,struct std::char_traits<char> > & __thiscall std::basic_ostream<char,struct std::char_traits<char> >::operator<<
(class std::basic_ostream<char,struct std::char_traits<char> > & (__cdecl*)(class std::basic_ostream<char,struct std::char_traits<char> > &))" (__imp_??6?$basic_ostream@DU?$char_traits@D@std@@@std@@QAEAAV01@P6AAAV01@AAV01@@Z@Z)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char> >
&,char const *)" (__imp_??6std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@0@AAV10@PBD@Z)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > std::cerr" (__imp_?cerr@std@@3V?$basic_ostream@DU?$char_traits@D@std@@@1@A)
jrtplibd.lib(rtppollthread.obj) : error LNK2001: unresolved external symbol "__declspec(dllimport) class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::endl(class std::basic_ostream<char,struct std::char_traits<char> > &)" (_
_imp_?endl@std@@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@1@AAV21@@Z)
Debug/testlib.ax : fatal error LNK1120: 17 unresolved externals

请问这该怎么解决啊?谢谢
--------------------
其他线索参考:
因为这个Dll开发需要,在Project|Settings|C/C++|Calling convention选择__stdcall. Settings|Link中选择了Ignore all default libraries.如果不选这个出现另一种link错误:
LIBCMTD.lib(dbgheap.obj) : error LNK2015: __malloc_dbg already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(dbgheap.obj) : error LNK2015: __free_dbg already defined in msvcrtd.lib(MSVCRTD.dll)
LIBCMTD.lib(crt0init.obj) : error LNK2015: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBCMTD.lib(crt0init.obj) : error LNK2015: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)...
回复

使用道具 举报

0

主题

32

帖子

27.00

积分

新手上路

Rank: 1

积分
27.00
发表于 2020-5-22 19:45:01 | 显示全部楼层
先恢复对 Ignore all default libraries 选项的修改.
可能是缺少头文件所致, 看起来象是需要包含 string.h
回复

使用道具 举报

1

主题

2

帖子

3.00

积分

新手上路

Rank: 1

积分
3.00
 楼主| 发表于 2020-5-31 03:00:02 | 显示全部楼层
Ignore all default libraries 去掉就像上边说的那种LNK2015错误一样。
错误应该是跟库文件有关,而不是include .h文件吧……因为我在.exe项目中应用jrtplib完全正常,没有涉及__declspec(dllimport)之类的东东
回复

使用道具 举报

0

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-9-4 10:30:01 | 显示全部楼层
各位,我遇到一个差不多的问题:error LNK2001: unresolved external symbol "__declspec(dllimport) public: class _com_ptr_t<class _com_IIID<struct _Connection,&struct __s_GUID _GUID_00001550_0000_0010_8000_00aa006d2ea4> > __thiscall CADOConnection::GetConnection(void)求救啊!!!!
回复

使用道具 举报

0

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-9-5 11:45:01 | 显示全部楼层
我遇到这个问题的时候是因为外部友元函数设为inline的原因。去掉inline就好了。不知道楼主什么原因。可以试一下。
回复

使用道具 举报

0

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-9-5 12:00:01 | 显示全部楼层
就是缺少引用库所致。
楼主可以检查一下自己所引用的库和头文件。
回复

使用道具 举报

0

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-9-6 17:00:01 | 显示全部楼层
库文件
回复

使用道具 举报

0

主题

1

帖子

2.00

积分

新手上路

Rank: 1

积分
2.00
发表于 2020-9-6 17:15:01 | 显示全部楼层
看看,这个库的头文件是否include了,还有看看你的lib放到附加库目录指向的位置了没有,有可能是lib没找到的原因
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

快速回复 返回顶部 返回列表