c++ - 编译旧的 C++ unix 应用程序以在 windows 中使用

标签 c++ gcc cygwin

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

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

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

最佳答案

库中的 C 代码(library/linpack 和 library/recipes)编译良好,使用:

gcc -c *.c

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

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 年,因此必须努力破解它以使其更新是不合理的。

祝你好运!

关于c++ - 编译旧的 C++ unix 应用程序以在 windows 中使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/442139/

相关文章:

c++ - 是否嵌套枚举类?

c++ - 编译期间 Unresolved external 错误

linux - LLVM 上的系统调用/sysenter

console - cygwin + console2 ctrl-c 键盘中断不起作用

c++ - 我应该在工作的 C++ 代码中的什么地方引入默认构造函数,为什么?

GCC:在使用静态数组时避免长时间链接

c++ - GCC编译时无法生成目标文件

vim - 为 cygwin 构建 vim——无终端库

installation - 我可以编写Cygwin安装脚本以包括某些软件包吗?

c++ - 使用立即模式绘制纹理的 OpenGL 替代方案?