编译旧的C ++ unix应用程序以便在Windows中使用

时间:2009-01-14 06:50:56

标签: c++ gcc cygwin

我需要为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

3 个答案:

答案 0 :(得分: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下使用GCC 3.4.4在Cygwin上。

我不是C ++大师 - 尽管我公平地分享了软件考古学 - 但我认为你需要更新代码以使用C ++标准头文件,因为特别缺少strstream.h(所以,名义上,使用<strstream>代替),这意味着你将不得不处理std命名空间等。此代码在标准之前提前了5年,因此必须努力破解标准并不是不合理的。

祝你好运!

答案 1 :(得分:0)

我可以想到两种可能性:AT&amp; T同时提供UWIN(可能与Cygwin不同,以避免同样的麻烦)和old versions of CFront的源代码(可能是原始编译器)使用)。

嗯,还有第三种可能性,我认为这是建议的操作:编辑源代码并使其达到标准的最新状态。如果您打算对此代码进行任何进一步的开发,最好尽快咬紧牙关。

答案 2 :(得分:0)

您仍然可以从GNU网站下载gcc 2.7.0的源代码。

您可以下载并制作旧版本的编译器。