将一个大型C项目从Unix移植到Windows。

时间:2021-12-28 15:07:32

So, I have a large C project that was built entirely on Unix (SPARC Solaris). me and several others have begun to revisit it because their was some interest in a windows build.

因此,我有一个很大的C项目,它完全建立在Unix (SPARC Solaris)上。我和其他一些人已经开始重新审视它,因为他们对windows构建感兴趣。

none of us have done this with a project of such size, so for starters, has anyone ported something from unix to windows and could maybe give me some pointers or how they did it.

我们中没有人做过这样规模的项目,所以对于初学者来说,任何人都可以从unix移植到windows上,或者可以给我一些建议,或者他们是怎么做的。

our first step on our plan was to decide on a compiler/dev environment.

我们计划的第一步是决定编译器/开发环境。

it seems that our options are MS Visual Studio, Cygwin, mingw/gcc, and Windows Services for UNIX (SFU).

我们的选择似乎是Visual Studio, Cygwin, mingw/gcc,以及UNIX (SFU)的Windows服务。

we are on a fairly short timetable so we want to rewrite as little code as possible.

我们的时间表很短,所以我们希望尽可能地重写代码。

so, Deciding on a compiler.

所以,决定编译器。

Another issue is that the code does use POSIX thread commands (pthread, etc)

另一个问题是代码确实使用了POSIX线程命令(pthread等)

we would prefer to compile natively, not using some sort of layer between the executable and the OS. unfortunatly with the pthread calls in our code, this may not be possible.

我们更希望采用本机编译,而不是在可执行文件和操作系统之间使用某种层。不幸的是,在我们的代码中有pthread调用,这可能是不可能的。

I believe both Cygwin and SFU do just that. Cygwin has a .dll that must be included in compiled code to work. I am not sure about SFU, any information about that would be greatly appreciated. It seems like it would be a good option but was developed to allow for UNIX compiled software to run on a windows machine with SFU, not any old windows box.

我相信Cygwin和SFU都这么做。Cygwin有一个.dll,必须包含在编译代码中才能工作。关于SFU我不太确定,如果有任何关于SFU的信息,我将非常感谢。这似乎是一个不错的选择,但它被开发出来,允许UNIX编译软件在windows机器上运行SFU,而不是任何旧的windows框。

mingw does have the ability to create native exes, but lacks the POSIX support.

mingw确实具有创建本地exes的能力,但是缺少POSIX支持。

So, can anyone give me any more information, suggestions, knowledge on any of these compilers in this context. or any experience they have with this sort of thing, it is greatly appreciated.

所以,谁能给我更多关于这些编译器的信息,建议和知识。或者他们在这类事情上的任何经验,我们都非常感激。

3 个解决方案

#1


7  

Short timetable? CygWin, plain and simple.

短的时间表?CygWin,平原和简单。

Despite your preference to not use a layer, that's going to provide the fastest path and you don't seem to indicate that the timeframe requirement is flexible.

尽管您倾向于不使用层,但这将提供最快的路径,而且您似乎不认为时间框架需求是灵活的。

We've ported both command-line and X-based UNIX programs to Windows using CygWin with minimal hassle.

我们已经将基于命令行和基于x的UNIX程序都移植到使用CygWin的Windows系统中,并且减少了麻烦。

#2


3  

Cygwin is likely the fastest path to a working executable. However it will leave you with some interesting distribution choices. Most obviously, cygwin.dll becomes a dependency. Its licensed GPL, unless you pay money to buy commercial use rights.

Cygwin可能是运行可执行文件的最快路径。但是它会给你一些有趣的分布选择。最明显的是,cygwin。dll变成依赖。它的许可GPL,除非你花钱购买商业使用权。

Cygwin is not particularly friendly to an ordinary Windows user. Its goal is to provide a full POSIX experience on Windows, supplying a shell, all the familiar *nix utilities, and even a port of X. However, it also remaps the Windows disk drive naming into a POSIX-like file system. I've never attempted to distribute an application built for Cygwin to machines that don't already have a full Cygwin installation. I will note that to my knowledge none of the big well-known open-source applications with Windows ports are based on Cygwin.

Cygwin对普通Windows用户不是特别友好。它的目标是在Windows上提供完整的POSIX体验,提供shell、所有熟悉的*nix实用程序,甚至是x的端口。我从未尝试过将为Cygwin构建的应用程序分发给没有完整的Cygwin安装的机器。我要指出的是,据我所知,没有一个著名的开源软件的Windows端口是基于Cygwin的。

If the only hard POSIX dependency you have is pthreads, then that is solvable. There is a pthreads port built on native Windows threads that works well with MinGW. IIRC, it is even distributed along with MinGW, or at least is one of their core supported packages.

如果唯一的硬POSIX依赖项是pthreads,那么它就是可解的。有一个构建在本地Windows线程上的pthreads端口,可以很好地与MinGW一起工作。IIRC甚至与MinGW一起分布,或者至少是它们的核心支持包之一。

If the rest of your handling of file names is largely as opaque strings, you may not even need to care about changing / to \. The Windows API is generally happy to treat either character as a path separator, even mixed in the same name. It is the CMD.EXE and early DOS convention of using / for command line options that prevents the use of / for pathnames at the command prompt, not the underlying Windows API.

如果您处理文件名的其余部分主要是不透明的字符串,那么您甚至不需要关心更改/到\。Windows API通常很乐意将两个字符作为路径分隔符,甚至将其混合在同一个名称中。CMD。EXE和早期DOS约定使用/用于命令行选项,防止在命令提示符中使用/用于路径名,而不是底层的Windows API。

For tools that might make porting your build process easier, check out the MSYS component of MinGW. It provides a lightweigh fork from the Cygwin environment in which enough *nix utilities are available to generally run ./configure and similar processes.

对于可能使移植构建过程更容易的工具,请查看MinGW的MSYS组件。它提供了一个来自Cygwin环境的lightweight fork,其中有足够的*nix实用程序可以正常运行。

In addition, the GnuWin32 project has ports of a large number of utilities and libraries that are all built to run as native Windows applications without unusual dependencies.

此外,GnuWin32项目具有大量实用程序和库的端口,这些工具和库都是作为本地Windows应用程序构建的,没有异常的依赖关系。

#3


2  

If the code is (at least mostly) portable and the only major issue is the use of pthreads, you might want to use the Pthreads Win32 library. While incomplete, it's sufficiently complete and accurate to deal with most pthreads code I've tried it with. While normally built as a DLL, this can also be built as a static library to avoid creating an extra dependencies in your executable.

如果代码(至少大部分是)可移植的,惟一的主要问题是使用pthreads,您可能希望使用pthreads Win32库。虽然不完整,但对于我尝试过的大多数pthreads代码来说,它已经足够完整和准确了。虽然通常构建为DLL,但也可以构建为静态库,以避免在可执行文件中创建额外的依赖项。

That, of course, leaves everything else to port -- but you haven't said enough to even guess whether porting the rest within your timeframe is at all reasonable.

当然,这就把其他的一切都留给了移植——但是您还没有说足够的话来猜测在您的时间范围内移植其余的部分是否完全合理。

#1


7  

Short timetable? CygWin, plain and simple.

短的时间表?CygWin,平原和简单。

Despite your preference to not use a layer, that's going to provide the fastest path and you don't seem to indicate that the timeframe requirement is flexible.

尽管您倾向于不使用层,但这将提供最快的路径,而且您似乎不认为时间框架需求是灵活的。

We've ported both command-line and X-based UNIX programs to Windows using CygWin with minimal hassle.

我们已经将基于命令行和基于x的UNIX程序都移植到使用CygWin的Windows系统中,并且减少了麻烦。

#2


3  

Cygwin is likely the fastest path to a working executable. However it will leave you with some interesting distribution choices. Most obviously, cygwin.dll becomes a dependency. Its licensed GPL, unless you pay money to buy commercial use rights.

Cygwin可能是运行可执行文件的最快路径。但是它会给你一些有趣的分布选择。最明显的是,cygwin。dll变成依赖。它的许可GPL,除非你花钱购买商业使用权。

Cygwin is not particularly friendly to an ordinary Windows user. Its goal is to provide a full POSIX experience on Windows, supplying a shell, all the familiar *nix utilities, and even a port of X. However, it also remaps the Windows disk drive naming into a POSIX-like file system. I've never attempted to distribute an application built for Cygwin to machines that don't already have a full Cygwin installation. I will note that to my knowledge none of the big well-known open-source applications with Windows ports are based on Cygwin.

Cygwin对普通Windows用户不是特别友好。它的目标是在Windows上提供完整的POSIX体验,提供shell、所有熟悉的*nix实用程序,甚至是x的端口。我从未尝试过将为Cygwin构建的应用程序分发给没有完整的Cygwin安装的机器。我要指出的是,据我所知,没有一个著名的开源软件的Windows端口是基于Cygwin的。

If the only hard POSIX dependency you have is pthreads, then that is solvable. There is a pthreads port built on native Windows threads that works well with MinGW. IIRC, it is even distributed along with MinGW, or at least is one of their core supported packages.

如果唯一的硬POSIX依赖项是pthreads,那么它就是可解的。有一个构建在本地Windows线程上的pthreads端口,可以很好地与MinGW一起工作。IIRC甚至与MinGW一起分布,或者至少是它们的核心支持包之一。

If the rest of your handling of file names is largely as opaque strings, you may not even need to care about changing / to \. The Windows API is generally happy to treat either character as a path separator, even mixed in the same name. It is the CMD.EXE and early DOS convention of using / for command line options that prevents the use of / for pathnames at the command prompt, not the underlying Windows API.

如果您处理文件名的其余部分主要是不透明的字符串,那么您甚至不需要关心更改/到\。Windows API通常很乐意将两个字符作为路径分隔符,甚至将其混合在同一个名称中。CMD。EXE和早期DOS约定使用/用于命令行选项,防止在命令提示符中使用/用于路径名,而不是底层的Windows API。

For tools that might make porting your build process easier, check out the MSYS component of MinGW. It provides a lightweigh fork from the Cygwin environment in which enough *nix utilities are available to generally run ./configure and similar processes.

对于可能使移植构建过程更容易的工具,请查看MinGW的MSYS组件。它提供了一个来自Cygwin环境的lightweight fork,其中有足够的*nix实用程序可以正常运行。

In addition, the GnuWin32 project has ports of a large number of utilities and libraries that are all built to run as native Windows applications without unusual dependencies.

此外,GnuWin32项目具有大量实用程序和库的端口,这些工具和库都是作为本地Windows应用程序构建的,没有异常的依赖关系。

#3


2  

If the code is (at least mostly) portable and the only major issue is the use of pthreads, you might want to use the Pthreads Win32 library. While incomplete, it's sufficiently complete and accurate to deal with most pthreads code I've tried it with. While normally built as a DLL, this can also be built as a static library to avoid creating an extra dependencies in your executable.

如果代码(至少大部分是)可移植的,惟一的主要问题是使用pthreads,您可能希望使用pthreads Win32库。虽然不完整,但对于我尝试过的大多数pthreads代码来说,它已经足够完整和准确了。虽然通常构建为DLL,但也可以构建为静态库,以避免在可执行文件中创建额外的依赖项。

That, of course, leaves everything else to port -- but you haven't said enough to even guess whether porting the rest within your timeframe is at all reasonable.

当然,这就把其他的一切都留给了移植——但是您还没有说足够的话来猜测在您的时间范围内移植其余的部分是否完全合理。