编译连接x86静态库的x64动态库时,LNK2001和LNK1120 [英] LNK2001 and LNK1120 when compiling a x64 dynamic library linking a x86 static library

查看:575
本文介绍了编译连接x86静态库的x64动态库时,LNK2001和LNK1120的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近被分配到一个c ++项目,虽然我不是一个c ++开发人员。我作为IDE提供了Visual Studio 2010 Professional。所以我给它一枪。



我要编写一个包含两个静态库(* .lib)的c ++动态库(* .dll)。静态图书馆是我们几年前从另一家公司购买的第三方图书馆。使用 dumpbin / header ... cmd调用,我可以说两个静态库都有以下文件头值:

  14C机器(x86)

我得到了这个任务为Win32解决方案平台工作。我将头文件和库添加到项目中。通过在.cpp中编写两个 #pragma comment(lib,...)语句来包含这些库,我需要这些功能。像一个魅力一样工作。一个示例函数如下所示:

  externCvoid OURFreeStringBuf(Cm_StringBuf * sbuf)
{
FreeStringBuf(sbuf); //对静态库的调用
}

此动态库将用于x64架构。所以我试图将解决方案平台设置为x64。现在我为每个静态库函数的调用发现以下错误(没有代码更改或其他配置更改):

  error LNK2001:未解析的外部符号...

后面是一个总结错误: / p>

 错误LNK1120:29未解决的外部链接

这些错误是否是尝试将x86 lib文件链接到x64 dll中的结果?有没有机会使用提供的静态库完成此任务?



非常感谢您提前。

解决方案

您不能 - 换句话说,没有办法 - 将32位库与64位可执行文件或DLL(或32位可执行文件)链接到64位可执行文件,位DLL,反之亦然)。您将不得不将.DLL / .EXE编译为32位,或者找到64位版本的32位库。没有其他解决方案!



64位架构在多个方面与32位架构不同,但最重要的是地址(指针)是64位一个64位架构,可防止几乎任何32位代码在64位环境中正常工作(因为地址的高32位丢失,不会产生任何有意义的)。


I recently got assigned to a c++ project, although I am not a c++ developer. I was provided Visual Studio 2010 Professional as IDE. So I gave it a shot.

I am to write a c++ dynamic library (*.dll) which wraps two static libraries (*.lib). The static libraries are third party libraries we bought a couple of years ago from another company. Using the dumpbin /header ... cmd call, I can say that both static libraries have the following file header value:

14C machine (x86)

I got this task working for the Win32 solution platform. I added the header files and the libraries to the project. The libraries are included by writing two #pragma comment(lib, ...) statements within the .cpp I need the functions in. Works like a charm. A sample function looks like this:

extern "C" void OURFreeStringBuf(Cm_StringBuf *sbuf)
{
    FreeStringBuf(sbuf); // the call to the static library
}

This dynamic library is to be used in x64 architectures, aswell. So I tried to set the solution platform to x64. Now I get the following error for each call of one of the static libraries' functions (no code changes or other configuration changes were made):

error LNK2001: unresolved external symbol "..."

followed by a summarizing error:

error LNK1120: 29 unresolved external links

Could these errors be the result of trying to link x86 lib files in a x64 dll? Is there any chance to complete this task using the provided static libraries?

Thank you very much in advance.

解决方案

You can not - in other words, there is NO WAY to - link a 32-bit library with a 64-bit executable or DLL (or a 32-bit executable to a 64-bit DLL or vice versa). You will either have to compile your .DLL/.EXE as 32-bit, or find a 64-bit version of the 32-bit library. No other solution!

The 64-bit architecture is different from the 32-bit architecture in several aspects, but most importantly, the addresses (pointers) are 64-bit in a 64-bit architecture, which prevents almost any 32-bit code from working correctly in a 64-bit environment (because the upper 32 bits of the addresses are lost, which doesn't produce anything meaningful).

这篇关于编译连接x86静态库的x64动态库时,LNK2001和LNK1120的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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