如何运行为旧编译器编写的程序?
我正在寻找混合树的实现(不重要),并找到一个“旧”一个here。如何运行为旧编译器编写的程序?
笔者说,他们已经尝试了SUN的Sparc平台(运行的Solaris 2.6),并与GCC-2.8.1编译这个代码。我的环境是gcc版本4.4.3(Ubuntu 10.10)。
的问题是: 我跑“做”与他提供了生成文件,但它给了我很多的错误信息如下:
g++ -c Node.C
g++ -c DataNode.C
In file included from DataNode.h:18,
from DataNode.C:17:
Query.h:9:20: error: vector.h: No such file or directory
Query.h:10:19: error: stack.h: No such file or directory
Query.h:13:22: error: function.h: No such file or directory
Query.h:14:22: error: iostream.h: No such file or directory
DataNode.C:283:8: warning: extra tokens at end of #endif directive
In file included from DataNode.h:18,
from DataNode.C:17:
Query.h:29: warning: ‘typedef’ was ignored in this declaration
Query.h:44: warning: ‘typedef’ was ignored in this declaration
Query.h:86: error: expected initializer before ‘<’ token
Query.h:118: error: ISO C++ forbids declaration of ‘PQ’ with no type
Query.h:118: error: expected ‘;’ before ‘*’ token
Query.h:122: error: ISO C++ forbids declaration of ‘PQ’ with no type
Query.h:122: error: expected ‘;’ before ‘*’ token
Query.h:126: error: ISO C++ forbids declaration of ‘PQ’ with no type
Query.h:126: error: expected ‘;’ before ‘*’ token
Query.h:135: error: expected initializer before ‘<’ token
DataNode.C: In member function ‘void DataNode::DisconnectBranch(int)’:
DataNode.C:80: error: ‘memmove’ was not declared in this scope
make: *** [DataNode.o] Error 1
我知道我需要修改的烃源代码,以便与现代编译器一致,如更改vector.h
至vector
。但我觉得这只是无穷无尽的。
所以我的问题是:是否有任何convienent方法来运行此程序,无论将此代码自动转换为“现代风格”还是使用独立的“旧式”编译器?
有什么建议吗?
=== 更新: ===
谢谢大家,我用--prefix=/usr/local/gcc-2.8.1
和修改 “Makefile文件” 要使用本老版本的GCC(/usr/local/gcc-2.8.1/bin/gcc
)安装gcc2.8.1在不同的目录。但是,当我运行“make”,但它仍然给了我找不到头的错误:
/usr/local/gcc-2.8.1/bin/gcc -c DataNode.C
In file included from DataNode.h:18,
from DataNode.C:17:
Query.h:9: vector.h: No such file or directory
Query.h:10: stack.h: No such file or directory
Query.h:11: deque: No such file or directory
Query.h:12: algorithm: No such file or directory
Query.h:13: function.h: No such file or directory
Query.h:14: iostream.h: No such file or directory
make: *** [DataNode.o] Error 1
然后我试图使用find /usr/local/gcc-2.8.1 -name "*vector*"
找到/usr/local/gcc-2.8.1这些头,但一无所获。
那么这些老版本gcc的头在哪里呢?
首先尝试从错误消息中提到的系统头文件中删除“.h”。它可能会给你其他的错误,但只是尝试和修复他们一个接一个。
你可以自己制作一个包含矢量的vertor.h。这样你就可以非侵入地解决不兼容问题。
编辑:
您可能还需要在头文件(S)添加 using namespace std;
。这是 通常是一个坏主意,但这是一种情况,我会做它无论如何。
一旦你得到它的工作,我会推荐重写它使用新风格的头文件和命名空间。
导入命名空间是一个编译器,所以在它前面没有'#'! – ThiefMaster 2011-12-29 16:52:21
谢谢。将解决。我说我的C++是生锈的。 – 2011-12-29 17:37:45
Debian Lenny(oldstable)有gcc 3.4。这可能具有更好的向后兼容性。尝试为其余问题制作兼容性标头,并通过额外的-I
目录将其包含在内。包含vector
的vector.h
头文件。
做你自己的忙,并尽量不要触摸旧的代码。以不可预见的方式破解遗留代码很容易。
您可以尝试在QEMU上运行程序supports Solaris 2.6。唯一的问题可能是寻找安装光盘/映像。此外,还有人在eBay上以便宜的价格销售旧的Solaris盒子,你可能会拿到一盒。
GCC为非常旧的版本提供下载,如果您尝试更旧版本的编译器,您可能会获得更好的机会。
thx,我试过了,但还是不行。我已更新该帖子 – teloon 2011-12-30 10:49:09
gcc
有-fpermissive
选项:试试看看是否至少有一些错误消失。另外:尝试制作一个头文件,其中包含全部需要使用指令的头文件。例如,使含有stdinc.h
:
#include <vector>
#include <iostream>
#include <stack>
...
using std::vector;
using std::fstream;
...
替换所有提到的遗留C++头文件与单个包括stdinc.h
。旧的C++没有命名空间,所以即使你用using namespace std;
替换单个命令,冲突也不太可能发生。
如果唯一的事情就是
#include <vector.h>
到
#include <vector>
using namespace std;
为什么不尝试用sed?
grep for all包含查看是否有除C++头以外的其他内容。如果不是你的幸运。
另一件更棘手的事情是,有一些旧代码依赖通过迭代器以非标准方式访问数据。我在一个用于linux的Doom地图编辑器中看到了这一点。那么你可能需要做手动的东西。
他特别要求解决方案,而不是重命名标题。 – 2011-12-29 15:12:23
另外,重命名头文件甚至没有接近尾部。如果你走这条路线,你也必须担心命名空间 - 例如''将所有东西放在'std'中,而''不放。 –
cHao
2011-12-29 15:21:58