使用 VC++ 2008 编译引用 STLport-5.1.4 的应用程序时出现 LNK2001 错误

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

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

问题描述

我为长篇文章提前道歉...

I apologize in advance for the long post...

当我们在 VS 菜单 > 工具 > 选项 > VC++ 目录 > 包含和库文件的目录下列出 STLPort 包含和库目录时,我曾经能够构建我们的 VC++ 解决方案(我们在 VS 2008 上).但是,我们希望过渡到完全依赖 .vcproj 和 .sln 文件的构建过程.与必须在每台开发 PC 上单独配置的 VS 选项不同,这些可以签入源代码管理.我们通过将包含目录添加到每个项目的属性页 > 配置属性 > C/C++ > 常规 > 附加包含目录,并将库目录添加到链接器 > 常规 > 附加库目录来处理大多数库的转换.

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.

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

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@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@stlp_std@@000JW4MessageTypeH0@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 最近在 旧的新事物——这些问题的一个原因是库是用一组开关编译的,但你的应用程序使用的是不同的开关.你需要做的是:

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:

获取链接器正在寻找的确切符号.这将是一个可怕的混乱的名字.使用十六进制编辑器(IIRC,Visual Studio 将执行此操作)查看您要链接到的 .lib 文件.找到几乎是链接器正在寻找的符号,但不完全是.鉴于符号的差异,尝试找出哪些命令行开关会有所帮助.祝你好运——对于不习惯这类问题的人来说,解决方案可能需要几天时间才能弄清楚 (!)

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 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 VC++ 2008 编译引用 STLport-5.1.4 的应用程序时出现 LNK2001 错误

基础教程推荐