代码之家  ›  专栏  ›  技术社区  ›  okutane

编译旧的C++ UNIX应用程序在Windows中的应用

  •  0
  • okutane  · 技术社区  · 16 年前

    我需要一个windows可执行文件,用于一些1994年为UNIX编写的代码。我试着在cygwin环境下这样做。C++标准从这个时候和标准库也被改变了。

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

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

    3 回复  |  直到 16 年前
        1
  •  1
  •   Jonathan Leffler    16 年前

    库中的C代码(library/linpack和library/recipes)可以通过以下方式编译:

    gcc -c *.c
    

    C++代码更麻烦。在..中有标题/包括并要求-DANSI生成函数原型。它们没有申报 extern "C" 在标题中;它们被正确地包含在C++源DIR的标题中:

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

    所以,编译一个数据流。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++使用了标准的标题。h尤其缺失(因此,名义上,使用 <strstream> 相反),这意味着你必须处理 std 名称空间等等。这段代码比标准早了5年,所以很难对其进行黑客攻击以使其达到最新状态并非不合理。

    祝你好运

        2
  •  0
  •   Max Lybbert    16 年前

    我可以想到两种可能性:AT&T同时提供这两种服务 UWIN (可能与Cygwin有足够的不同,以避免相同的麻烦)以及 old versions of CFront (这可能是最初使用的编译器)。

    嗯,还有第三种可能性,我认为这是建议的措施:编辑源代码并使其符合标准。如果你打算对这段代码做进一步的开发,最好尽早完成。

        3
  •  0
  •   James Anderson    16 年前

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

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