gpt4 book ai didi

c++ - 如何运行为旧编译器编写的程序?

转载 作者:可可西里 更新时间:2023-11-01 18:26:47 25 4
gpt4 key购买 nike

我正在寻找混合树的实现(不重要),并找到一个“旧的”here .

作者说他们已经在 SUN Sparc 平台(运行 Solaris 2.6)和 gcc-2.8.1 编译器上尝试了这段代码。而我的环境是gcc version 4.4.3 (Ubuntu 10.10)。

问题是:我用他提供的 makefile 运行“make”,但它给了我很多如下错误信息:

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。但我发现它是无穷无尽的。

所以我的问题是:是否有任何方便的方法来运行这个程序,无论是自动将此代码转换为“现代风格”还是使用独立的“旧式”编译器?

有什么建议吗?

===更新:===

谢谢大家,我使用 --prefix=/usr/local/gcc-2.8.1 在不同的目录中安装了 gcc2.8.1 并修改了“makefile”以使用这个旧版本gcc(/usr/local/gcc-2.8.1/bin/gcc)。但是当我运行“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 的这些头在哪里?

最佳答案

你可以自己制作一个包含vector的vertor.h。这样您就可以无创地修复不兼容问题。

编辑:

您可能还需要添加一个 使用命名空间标准; 在头文件中。这是通常是个坏主意,但在这种情况下我无论如何都会这样做。

一旦你让它工作,我会建议重写它以使用新样式的头文件和命名空间。

关于c++ - 如何运行为旧编译器编写的程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8669323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com