使用 .lib 文件构建项目时的奇怪行为
我正在使用 Visual Studio 2008。我试图在我的源代码中使用 C++ 库。在我的计算机上安装该库后,我有一些包含文件和一些库文件。另外,bin文件夹中还有msvcm80.dll、msvcp80.dll和msvcr80.dll。
我在链接项目时遇到问题,我在下面解释了这一点。我在网上搜索但没有找到我的问题的相关答案。
我执行了以下过程:
我使用了 Explorer Lib 软件,发现 .lib 文件是在发布配置中内置的。
我将 Visual Studio 解决方案设置为以 32 位发布模式构建。我不确定是否应该使用 32 位还是 64 位。(下面我解释了当我将其更改为 x64 平台时会发生什么)。
我将库文件添加到链接器依赖项及其在附加库目录中的路径。
我在源代码中包含了头文件。
当我尝试构建解决方案时,我在源代码中调用的函数上收到错误“LNK2001:无法解析的外部符号”。即使我删除了库依赖项并删除了链接器配置中的路径,我也会收到相同的错误。
我的问题是,为什么链接器没有在库文件中找到源代码中调用的函数?
当我将平台从 Win32 更改为 x64 时,我收到错误 LNK 2001,但在另一个函数上。不同之处在于,链接器抱怨一个我没有在源代码中直接调用的函数。
有人可以帮我找出这个错误的原因吗?如果我没有清楚地解释我的问题,请告诉我。
谢谢,
艾哈迈德
I am using visual studio 2008. I am trying to use a C++ library in my source code. After installing the library on my computer, I have some include files as well as some library files. In addition, in the bin folder there are msvcm80.dll, msvcp80.dll, and msvcr80.dll.
I have a problem in linking the project which I have explained below. I searched online but I didn't find a relative answer to my question.
I did the following procedures:
I used Explorer Lib software and found out that the .lib files are built in release configuration.
I set the visual studio solution to be built in release mode for 32 bit. I was not sure whether I should use 32 or 64. (Below I explained what happens when I change this to x64 platform).
I added the library files to the linker dependencies and their path in the additional library directories.
I included the header file in the source code.
When I try to build the solution, I get the error "LNK2001: unresolved external symbol" on the function that I called in my source code. I get the same error even if I remove the library dependency and delete their path in the linker configuration.
My question is that why the linker does not locate the called functions in my source code in the library files?
When I change the platform from Win32 to x64, I get the error LNK 2001 but on another function. The difference is that the linker is complaining about a function which I have not called directly in my source code.
Could someone kindly help me identify the cause of this error? Please let me know if I did not explain my problem clearly.
Thanks,
Ahmad
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须提供更多详细信息,也许是一些(第一个)错误消息。
在 VS 中正确设置链接器从来都不是一件容易的事。您可以检查一些要点:
如果使用winsock库,检查首先包含哪个,等等(著名的winsock.h与winsock2.h)
检查平台工具集(在你的情况下它可能应该是v80)
最后尤其重要的是,如果缺少的外部是 Windows API,则您可能需要在链接器\附加依赖项中指定以下内容:User32.lib、Shell32.lib、Oleaut32.lib、Advapi32.lib,具体取决于所使用的 API。
You must give more details, maybe some (of the first) error messages.
Getting the linker settings right in VS has never been an easy task. Some points you can check:
if using winsock libraries, check which is included first, etc. (the famous winsock.h vs winsock2.h)
Check the Platform Toolset (in your case it should probably be v80)
Last and not least, if the missing externals are Windows APIs maybe you need to specify in the Linker\Additional Dependencies things like: User32.lib, Shell32.lib,Oleaut32.lib,Advapi32.lib depending on the APIs used.