Linux 到 Windows C++ 端口
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4797184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Linux to Windows C++ port
提问by Petr
I am trying to port my C++ application from Linux to Windows (Visual C++). I am just curious wheter you know about any script/tool that would scan the source code and check for possible issues (such as dirent.h etc).
我正在尝试将我的 C++ 应用程序从 Linux 移植到 Windows (Visual C++)。我很好奇您是否了解任何可以扫描源代码并检查可能的问题(例如 dirent.h 等)的脚本/工具。
Thanks.
谢谢。
回答by asveikau
The first tool is called your compiler. It will tell you if your program compiles.
第一个工具称为编译器。它会告诉你你的程序是否编译。
The second tool is called running whatever tests you may have. They will tell you if the resulting binary works.
第二个工具称为运行您可能拥有的任何测试。他们会告诉您生成的二进制文件是否有效。
What were you looking for, a crystal ball to save you from doing work? Regardless of what approach you take or what you may read to help you get started, you will at some point have to (1) compile the thing and (2) check to see that it works.
你在找什么,一个可以让你免于工作的水晶球?无论您采用什么方法或阅读什么来帮助您入门,您在某个时候都必须 (1) 编译该事物并 (2) 检查它是否有效。
回答by Martin Beckett
http://www.mingw.org/wiki/msysor http://www.cygwin.com/
http://www.mingw.org/wiki/msys或 http://www.cygwin.com/
edit:
Cygwin is essentially a compatibility layer (implemented as a dll) between Unix/Posix and windows - the code should be unchanged, but there can be issues between different version of the cygwin dll.
编辑:
Cygwin 本质上是 Unix/Posix 和 Windows 之间的兼容层(作为 dll 实现) - 代码应该保持不变,但不同版本的 cygwin dll 之间可能存在问题。
Msys+Mingw is a subset of Unix/Posix libs reimplemented in win32 and a port of the gcc compiler plus essential build tools. The resulting exe runs completely natively but some complex build procedures need more work.
Msys+Mingw 是在 win32 中重新实现的 Unix/Posix 库的一个子集,也是 gcc 编译器的一个端口以及基本的构建工具。生成的 exe 完全在本地运行,但一些复杂的构建过程需要更多的工作。
Either way if the app uses X then you also need an X-server, both of these provide one. But if you are doing lots of graphics and the app is written using something like Qt or wxWidgets you are going to have a reasonable amount of pain getting it to work.
无论哪种方式,如果应用程序使用 X,那么您还需要一个 X 服务器,它们都提供一个。但是,如果您正在处理大量图形并且应用程序是使用 Qt 或 wxWidgets 之类的东西编写的,那么您将有相当多的痛苦才能让它工作。
回答by James
Microsoft has an entry on the MSDN about the 'best' ways to manage a port from *nix to Win32.
Microsoft 在 MSDN 上有一个关于管理从 *nix 到 Win32 的端口的“最佳”方法的条目。
回答by Mikael Persson
First, I would just compile using MinGW (at least at first), to eliminate any possible gcc to MSVS issues (not to waste time with compiler-related issues).
首先,我将只使用 MinGW 进行编译(至少在开始时),以消除任何可能的 gcc 到 MSVS 问题(不要在与编译器相关的问题上浪费时间)。
Second, just compile the code and watch all the include files that were not found. Go to the code that includes those headers, figure out if it is a dependency that exists in Windows (but was just not installed or set in include-paths). If not, use cross-platform libraries to replace the non-portable libraries. Typical cross-platform libraries would include: Boost, OpenGL, SDL, Qt, etc. (depending on how much your application is doing). If it is just a command-line "number-crunching" software, you will probably find all you need in Boost.
其次,只需编译代码并查看所有未找到的包含文件。转到包含这些标头的代码,确定它是否是 Windows 中存在的依赖项(但只是未在包含路径中安装或设置)。如果不是,请使用跨平台库替换不可移植的库。典型的跨平台库包括:Boost、OpenGL、SDL、Qt 等(取决于您的应用程序在做什么)。如果它只是一个命令行“数字运算”软件,那么您可能会在 Boost 中找到所需的一切。