从 VC6 迁移到 VC9 的编译问题
我正在将旧版 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我怀疑这个编译器错误将是唯一的问题。更新编译器几乎总是会带来少量问题。最好把这些矛盾解决掉,认真检验一下结果。我不认为某些“解决方法”会减少麻烦,因为编译器无论如何都是不同的。
并行使用不同编译器时解决此类问题的唯一解决方案是条件编译,例如:
请注意,编号
_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:
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.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
抱歉,您遇到了很多问题。
首先是基础知识:
是一个较旧的 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 headershould 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++.