编译使用VC ++ 2008引用STLport-5.1.4的应用程序时出现LNK2001错误 [英] LNK2001 error when compiling apps referencing STLport-5.1.4 with VC++ 2008

查看:280
本文介绍了编译使用VC ++ 2008引用STLport-5.1.4的应用程序时出现LNK2001错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为长期邮件提前道歉...



我以前能够建立我们的VC ++解决方案(我们在VS 2008),当我们列出VS菜单>工具>选项> VC ++目录>包含和库文件目录下的STLPort包含和库目录。但是,我们希望转换到完全依赖于.vcproj和.sln文件的构建过程。这些可以检查源代码控制不像VS选项,必须在每个开发PC上单独配置。我们通过将Include目录添加到每个项目的属性页>配置属性> C / C ++>常规>其他包含目录,以及库目录到链接器>常规>其他库目录来处理大多数库的转换。



不幸的是,这种方法不适用于STLPort。在链接期间,我们得到LNK2019和LNK2001错误:

 错误1错误LNK2019:未解析的外部符号public:virtual bool __thiscall MyClass :: myFunction(class stlp_std :: basic_istream< char,class stlp_std :: char_traits< char>&,class MyOtherClass&,class stlp_std :: basic_string< char,class stlp_std :: char_traits< char>,class stlp_std :: allocator< ; char>>&)const(?myFunction @ MyClass @@ UBE_NAAV?$ basic_istream @ DV?$ char_traits @ D @ stlp_std @@@ stlp_std @@ AAVSbprobScenarioData @ AAV?$ basic_string @ DV?$ char_traits @ D @ stlp_std @@ V?$ allocator @ D @ 2 @@ 3 @@ Z)在函数_main中引用MyLibrary.obj 

错误5错误LNK2001:未解析的外部符号public:static void __cdecl MyClass: :myFunction(class stlp_std :: basic_string< char,class stlp_std :: char_traits< char>,class stlp_std :: allocator< char>> const&,class stlp_std :: basic_string< char,class stlp_std :: char_traits< char> ,class stlp_std :: allocator< char> > const&,class stlp_std :: basic_string< char,class stlp_std :: char_traits< char>,class stlp_std :: allocator< char> > const&,class stlp_std :: basic_string< char,class stlp_std :: char_traits< char>,class stlp_std :: allocator< char> > const&,long,enum MyClass :: MessageType,int,class stlp_std :: basic_string< char,class stlp_std :: char_traits< char>,class stlp_std :: allocator< char> > const&)(?myFunction @ MyClass @@ SAXABV?$ basic_string @ DV?$ char_traits @ D @ stlp_std @@ V?$ allocator @ D @ @ stlp_std @@ 000JW4MessageType @ 1 @ H0 @ Z)MyLibrary。 lib

这种情况发生在链接和可执行项目到依赖项是库项目时,奇怪的是,这不会发生 /blogs.msdn.com/oldnewthing/archive/2008/12/29/9255240.aspxrel =nofollow>旧的新事物 - 这些问题的一个原因是库编译有一个你的应用程序使用的是不同的集合,你需要做的是:



获取链接器正在寻找的确切符号,它将是一个
使用十六进制编辑器(IIRC,Visual Studio会这样做)来查看你链接的.lib文件。
查找几乎是链接器正在寻找的符号,但不完全。
鉴于符号的不同,尝试找出什么命令行开关将有所帮助。
祝你好运 - 对于不习惯这种问题的人,解决方案可能需要几天才能找出(!)


I apologize in advance for the long post...

I used to be able to build our VC++ solutions (we're on VS 2008) when we listed the STLPort include and library directories under VS Menu > Tools > Options > VC++ Directories > Directories for Include and Library files. However, we wanted to transition to a build process that totally relies on .vcproj and .sln files. These can be checked into source control unlike VS Options which have to be configured on each development PC separately. We handled the transition for most libraries by adding the Include directories to each Project's Property Pages > Configuration Properties > C/C++ > General > Additional Include Directories, and Library directories to Linker > General > Additional Library Directories.

Unfortunately, this approach doesn't work for STLPort. We get LNK2019 and LNK2001 errors during linking:

Error   1	error LNK2019: unresolved external symbol "public: virtual bool __thiscall MyClass::myFunction(class stlp_std::basic_istream<char,class stlp_std::char_traits<char> > &,class MyOtherClass &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > &)const " (?myFunction@MyClass@@UBE_NAAV?$basic_istream@DV?$char_traits@D@stlp_std@@@stlp_std@@AAVSbprobScenarioData@@AAV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@3@@Z) referenced in function _main	MyLibrary.obj	

Error   5	error LNK2001: unresolved external symbol "public: static void __cdecl MyClass::myFunction(class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,long,enum MyClass::MessageType,int,class stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &)" (?myFunction@MyClass@@SAXABV?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@000JW4MessageType@1@H0@Z)	MyLibrary.lib

This happens while linking and executable project to dependencies which are library projects. Curiously, this does not happen while linking the library projects themselves. Any ideas?

解决方案

Raymond Chen recently talked about this at The Old New Thing-- one cause of these problems is that the library was compiled with one set of switches, but your app is using a different set. What you have to do is:

Get the exact symbol that the linker is looking for. It will be a horrible mangled name. Use a hex editor (IIRC, Visual Studio will do this) to look at the .lib file you're linking to. Find the symbol that's almost the thing the linker is looking for, but not quite. Given the differences in the symbols, try to figure out what command line switches will help. Good luck -- for people who aren't used to this sort of problem, the solution can take days to figure out (!)

这篇关于编译使用VC ++ 2008引用STLport-5.1.4的应用程序时出现LNK2001错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆