与使用早期版本的 Visual Studio 构建的第 3 方静态库链接时出错

发布于 2024-08-05 13:35:33 字数 536 浏览 6 评论 0原文

我正在开发一个链接到第三方静态库(本文称为 EXTERNALLIB)的项目。在 Visual Studio 2005 中,我能够链接到 EXTERNALLIB 并创建可用的可执行文件。现在我们使用 Visual Studio 2008,我收到以下错误:

fatal error C1047: The object or library file EXTERNALLIB was created with an older compiler than other objects; rebuild old objects and libraries.

有没有办法告诉编译器正确链接到 EXTERNALLIB?我相信问题可能与特定的调用约定(__stdcall、__cdecl、__clrcall、__thiscall)有关。我可以在新程序中指示旧库的正确调用约定吗?我是否可以向我们的供应商提供具体反馈(例如在头文件中使用 APIENTRY),以便将来的编译器升级时不会出现此问题?

代码是用 C++ 编写的。我无权访问 EXTERNALLIB 的代码,因此我无法自己重建它。

I am working on a project that links to a 3rd party static library (herin refered to as EXTERNALLIB). In Visual Studio 2005 I was able to link to EXTERNALLIB and create a usable executable. Now we are using Visual Studio 2008 and I am receiving the following error:

fatal error C1047: The object or library file EXTERNALLIB was created with an older compiler than other objects; rebuild old objects and libraries.

Is there a way for me to tell the compiler to correctly link to EXTERNALLIB? I believe the problem may be related to specific calling conventions (__stdcall, __cdecl, __clrcall, __thiscall). Can I indicate in the new program the correct calling convention for the old library? Is there specific feedback that I can give to our vendor (such as using APIENTRY in the header files) such that this problem does not occur with future compiler upgrades?

The code is writen in C++. I do not have access to the code for EXTERNALLIB and thus I am unable to rebuild it myself.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫弦 2024-08-12 13:35:33

您的问题可能是由“代码是用 C++ 编写的”引起的。 C++ 链接的 ABI 本质上完全没有被任何标准指定,并且众所周知,它在不同的编译器之间是可变的。我怀疑 VS 试图告诉您 ABI 再次更改,因此它无法直接链接到库。

如果想要在 DLL 中实现 C++ 对象,这个问题通常会加剧,但幸运的是,这里没有这个问题。

一种可行的解决方案的方法是使用可调用 C 的适配器来对 EXTERNALLIB 的已发布 API 进行皮肤处理,并将整个内容链接到 DLL 中。使用较旧的 VS 版本构建皮肤(最坏的情况下,仍然可以找到免费版本)。确保仅公开 extern "C" 函数。特别要确保 DLL 中没有公开任何全局对象(尽管它们可能需要存在于您的皮肤中)。

最好的答案是回到 EXTERNALLIB 的供应商那里,礼貌地报告无法与当前 VS 链接的错误,并请求重建版本。

You problem is likely to result from "the code is written in C++". The ABI for C++ linkage is essentially completely unspecified by any standard, and is notoriously changeable from compiler to compiler. I suspect that VS is trying to tell you that the ABI has changed again, and that as a result it cannot link directly to the library.

This problem is often exacerbated by wanting to implement C++ objects in a DLL, but luckily you don't have that problem here.

One approach to a solution that should work is to skin the published API of EXTERNALLIB with a C-callable adaptor, and to link that whole thing into a DLL. Build the skin with the older VS version (at worst, the free edition should still be findable). Make sure that only extern "C" functions are exposed. Especially make sure that no global objects are exposed from the DLL (although they may need to exist within your skin).

The best answer is go back to the supplier of EXTERNALLIB and politely report the failure to link with the current VS as a bug and request a rebuilt version.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文