0

对于 1994 年为 UNIX 编写的某些代码,我需要有一个 Windows 可执行文件。我试图从 cygwin 环境中做到这一点。从那时起,C++ 标准和标准库都发生了变化。

我尝试使用 -std= 和 -traditional-cpp 选项,但这些选项根本没有帮助我。我还发现 -fno-for-scope 和 -fno-operator-names 减少了错误的数量。从那时起,输入/输出库也发生了重大变化。我也认为从那时起预定义的(由预处理器)宏也有可能发生变化。

作者对代码的注释:
http ://research.microsoft.com/en-us/um/people/hoppe/code.htm

4

3 回答 3

1

库中的 C 代码(库/linpack 和库/食谱)使用以下代码编译得很好:

gcc -c *.c

C++ 代码更成问题。../include 中有头文件,它们需要 -DANSI 来生成函数原型。它们没有extern "C"在标题中声明;它们正确包含在 C++ 源目录的标题中:

extern "C" {
#include "linpack.h"
}

所以,编译 A3dStream.C,我得到:

$ g++ -DANSI -I../include -c A3dStream.C
In file included from /usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/iostream.h:31,
                 from Hh.h:12,
                 from A3dStream.C:4:
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/backward/backward_warning.h:32:2:
warning: #warning This file includes at least one deprecated or antiquated header.
Please consider using one of the 32 headers found in section 17.4.1.2 of the C++
standard.    Examples include substituting the <X> header for the <X.h> header for
C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable
this warning use -Wno-deprecated.
In file included from A3dStream.C:4:
Hh.h:15:23: strstream.h: No such file or directory
In file included from A3dStream.C:4:
Hh.h:45: error: declaration of C function `void bzero(void*, int)' conflicts with
/usr/include/string.h:54: error: previous declaration `void bzero(void*, size_t)' here
Hh.h:46: error: declaration of C function `int gethostname(char*, int)' conflicts with
/usr/include/sys/unistd.h:206: error: previous declaration `int gethostname(char*, size_t)' here
Hh.h:98: error: an explicit specialization must be preceded by 'template <>'
Hh.h:105: error: an explicit specialization must be preceded by 'template <>'
Hh.h:111: error: an explicit specialization must be preceded by 'template <>'
Hh.h:221: error: new declaration `void unsetenv(const char*)'
/usr/include/cygwin/stdlib.h:26: error: ambiguates old declaration `int unsetenv(const char*)'
In file included from Geometry.h:10,
                 from A3dStream.h:7,
                 from A3dStream.C:5:
Array.h: In member function `void Array<T>::resize(int)':
Array.h:40: error: `size' undeclared (first use this function)
Array.h:40: error: (Each undeclared identifier is reported only once for each function it appears in.)
Array.h:44: error: `a' undeclared (first use this function)
Array.h: In member function `void Array<T>::clear()':
Array.h:51: error: `a' undeclared (first use this function)
Array.h:51: error: `size' undeclared (first use this function)
Array.h: In member function `void Array<T>::init(int)':
Array.h:53: error: `size' undeclared (first use this function)
Array.h: In member function `void Array<T>::need(int)':
Array.h:57: error: `size' undeclared (first use this function)
Array.h: In member function `Array<T>& Array<T>::operator+=(const T&)':
Array.h:64: error: `a' undeclared (first use this function)
Array.h: In member function `void Array<T>::squeeze()':
Array.h:66: error: `size' undeclared (first use this function)
Array.h: In member function `const T& Array<T>::operator[](int) const':
Array.h:70: error: `a' undeclared (first use this function)
Array.h: In member function `T& Array<T>::operator[](int)':
Array.h:71: error: `a' undeclared (first use this function)

其他文件产生类似的错误集。

我在 Windows XP 下的 Cygwin 上使用 GCC 3.4.4。

我不是 C++ 大师——尽管我在软件考古方面做了相当多的工作——但在我看来,你需要更新代码以使用 C++ 标准头文件,因为 strstream.h 尤其缺失(所以,名义上,<strstream>改为使用),这意味着您必须处理std名称空间等。这段代码比标准早了 5 年,因此必须努力破解它以使其更新并不是没有道理的。

祝你好运!

于 2009-01-14T08:01:47.507 回答
0

I can think of two possibilities: AT&T offers both UWIN (which may be different enough from Cygwin to avoid the same trouble) and the source for old versions of CFront (which is probably the original compiler used).

Well, there's a third possibility, and I think it's the recommended action: edit the source and bring it up to date to the standard. If you intend to do any further development on this code, it's best to bite the bullet sooner rather than later.

于 2009-01-14T08:14:20.650 回答
0

You can still download the source for gcc 2.7.0 from the GNU web site.

You could download and make the older version of the compiler.

于 2009-01-14T08:31:50.287 回答