从 VC6 迁移到 VC9 的编译问题

发布于 2024-09-16 15:37:29 字数 750 浏览 14 评论 0原文

我正在将旧版 C++ 系统从 VC6 移植到 VC9。

应用程序 () 静态链接到内部应用程序 (内部开发,但由单独的团队开发)。 来自 的头文件的本地副本包含在 CPP 文件中,并在 中编译。

目前我们不打算迁移 到 VC9。虽然 将使用单独的 CRT,但预计不会发生冲突。

我们面临的问题是来自(本地副本)的包含文件未使用 VC9 进行编译。

致命错误 C1083:无法打开包含 文件:'iostream.h':没有这样的文件或 目录

可能的解决方案: 如果我在 的本地副本中进行更改并使用 VC9 进行编译,那么我不确定它是否会在运行时导致一些问题。

有没有其他方法可以让 VC9 使用 而不是 来编译 文件?

I am porting a legacy C++ system from VC6 to VC9.

The application (<APP A>) statically links to an internal application <APP B> ( developed in house but by a separate team).
A local copy of header files from <APP B> are included in CPP files and compiled in <APP A>.

Currently we are not planning to migrate <APP B> to VC9. Though both <APP A> and <APP B> will use the separate CRTs but no conflict expected.

The issue we are facing is that include files from ( local copy in ) are not getting compiled with VC9.

fatal error C1083: Cannot open include
file: 'iostream.h': No such file or
directory

Possible solutions:
If I make the changes in local copy of <APP A> and compile with VC9 then I am not sure if it can cause some problem during runtime.

Is there any other way in which I can ask VC9 to compile the <APP A> files with <iostream.h> instead of <iostream> ?

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

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

发布评论

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

评论(3

几味少女 2024-09-23 15:37:46

我怀疑这个编译器错误将是唯一​​的问题。更新编译器几乎总是会带来少量问题。最好把这些矛盾解决掉,认真检验一下结果。我不认为某些“解决方法”会减少麻烦,因为编译器无论如何都是不同的。

并行使用不同编译器时解决此类问题的唯一解决方案是条件编译,例如:

#if _MSC_VER >= 1200 
   // Code for VC 6.0 or higher goes here
#endif

请注意,编号 _MSC_VER 与 Visual Studio 版本的编号不同。
对于 Visual Studio 2010,即 _MSC_VER 定义为 1600。

I doubt that this compiler error will be the only problem. Updating the compiler almost always introduces a small number of problems. Its best to solve these conflicts and to test the result seriously. I dont thing that some "Workaround" will make less trouble as the compiler is different anyway.

The only solution to solve such problems when using different compilers in parallel is conditional compilation such as:

#if _MSC_VER >= 1200 
   // Code for VC 6.0 or higher goes here
#endif

Be aware that the number _MSC_VER differs from that of the Version of Visual Studio.
For Visual Studio 2010, i.e _MSC_VER is defined as 1600.

紫轩蝶泪 2024-09-23 15:37:43

Michael Feathers 有一本很棒的书 http://www.amazon.com/Working-有效地-Legacy-Michael-Feathers/dp/0131177052,关于此类项目。

简而言之,如果您有测试,请进行所需的更改和重构,然后重新运行测试。对于您的示例,我将使用预处理器指令根据编译器版本选择正确的包含,然后修复任何损坏的测试。

如果没有测试,你会遇到更多麻烦,你要么写它们,要么祈祷不要破坏任何东西

There is a great book by Michael Feathers http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052, about this type of project.

The short answer is if you have tests, make the required changes and refactorings and rerun your tests. For your example, I would use a preprocessor directive to pick the right include based on compiler version, and then fix any broken tests.

Without tests you're in a bit more trouble, you'll have either write them or pray you don't break anything

峩卟喜欢 2024-09-23 15:37:41

抱歉,您遇到了很多问题。

首先是基础知识: 是一个较旧的 Microsoft 标头,用于定义 ::cout 等。 是标准标头,并定义例如 std::cout。您可以使用这两个,但是这个标头
不应该包含在APP.H中。 不定义您在声明中使用的类型。大概您依赖于 VC6 实现的工件,即 引入 。您可能想切换到 ,它旨在用于标头中。

然而,更大的问题是您假设您可以将“APP A”和 APP B”链接在一起,即使它们是用 VC6 和 VC9 编译的。这是真的当且仅它们共享 < code>extern "C" API。C++ 名称修饰在它们之间是(故意的)不同,并且因为您提到了 而不是 。 ;,我假设你的共同点确实是 C++。

Sorry, but you're in a load of problems.

First the basics: <iostream.h> is an older Microsoft header, that was used to define e.g. ::cout. <iostream> is the Standard header, and defines e.g. std::cout. You can use both of those, but this header
should not be included in APP.H. <iostream> does not define types that you'd use in declarations. Presumably you're relying on an artifact of the VC6 implementation, namely that <iostream.h> pulled in <istream.h> and <ostream.h>. You might want to switch to <iosfwd> instead, which is intended to be used in headers.

The bigger problem is however your assumption that you can just link "APP A" and APP B" together, even though they are compiled with VC6 and VC9. This is true if and only if they share an extern "C" API. C++ name mangling is (intentionally) different between them. And since you mentioned <iostream.h> instead of <stdio.h>, I'm going to assume that your common is really C++.

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