windows 将 Visual Studio C++ 移植到 Linux
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3298053/
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
Port Visual Studio C++ to Linux
提问by MBZ
We have a not very complicated but big(i.e. lots of files) Visual Studio C++ Win32 Console written in C++0x standard in VS2010. It does not use any non standard code or anything (Hopefully!).
我们有一个不是很复杂但很大(即很多文件)的 Visual Studio C++ Win32 控制台,它是在 VS2010 中用 C++0x 标准编写的。它不使用任何非标准代码或任何东西(希望如此!)。
I now wanna port it to Linux. Which way is the quickest way to do it? autoconf? old-fashioned make file? any other solution?
我现在想将它移植到 Linux。哪种方式是最快的方法?自动配置?老式的make文件?任何其他解决方案?
采纳答案by Amardeep AC9MF
I would use regular make but keep it simple with default rules as much as possible. Add in dependencies as you go along.
我会使用常规 make 但尽可能使用默认规则保持简单。继续添加依赖项。
EDIT:As in interim step, build it with mingw so that you can avoid the whole API porting issue until you have a working build in your new build mechanism.
编辑:在临时步骤中,使用 mingw 构建它,这样您就可以避免整个 API 移植问题,直到您在新构建机制中有一个工作构建。
If your console app calls win32 API functions then you have a choice between modifying all the source where it is used or writing a module that implements those functions.
如果您的控制台应用程序调用 win32 API 函数,那么您可以选择修改所有使用它的源代码或编写实现这些函数的模块。
In prior porting efforts of this type I tried it both ways and the latter was easier. I ended up writing only about 18 to 20 shim functions.
在之前的这种类型的移植工作中,我尝试了两种方法,后者更容易。我最终只编写了大约 18 到 20 个填充函数。
It was successful enough that I ended up writing an OS abstraction layer that was used on many projects that simply let me compile on Windows native, cygwin, Linux, VxWorks, etc. with trivial changes to one or two files.
它非常成功,以至于我最终编写了一个操作系统抽象层,该层用于许多项目,这些项目只是让我在 Windows 本机、cygwin、Linux、VxWorks 等上进行编译,只需对一两个文件进行微不足道的更改。
(p.s. Any interest in an open source version of a C++ based OS abstraction layer? I was thinking of releasing an unencumbered version of it to the world if there's sufficient interest. It's mostly useful where BOOST is too heavy -- i.e. embedded projects.)
(ps 对基于 C++ 的操作系统抽象层的开源版本感兴趣吗?如果有足够的兴趣,我正在考虑向世界发布它的无障碍版本。它在 BOOST 太重的情况下最有用 - 即嵌入式项目。)
回答by Alex B
Most probably you don't need autoconf (and I suggest you don't touch it, unless you love pain), because you are not trying to be portable to a dozen of Unix flavours.
很可能你不需要 autoconf(我建议你不要碰它,除非你喜欢痛苦),因为你不想移植到十几种 Unix 风格。
- Roll your Makefiles manually. It shouldn't be too difficult if you have a set of shared rules and have minimal Makefiles that just specify source files and compile options.
- Use GCC 4.5 as it supports more C++0x features.
- 手动滚动你的 Makefile。如果您有一组共享规则并且只有最少的 Makefile 仅指定源文件和编译选项,那应该不会太难。
- 使用 GCC 4.5,因为它支持更多 C++0x 特性。
回答by graham.reeds
You can export a make file from Visual Studio.
您可以从 Visual Studio 导出生成文件。
Update: Actually you can't anymore, unless you have VC6 lying around
更新:实际上你不能了,除非你有 VC6 躺在身边
回答by rubenvb
STAY AWAY FROM AUTO* and configure. These are horrible IMHO.
远离自动*并进行配置。这些是可怕的恕我直言。
If you can somehow get a VS 8 or 9 vcproj/sln, you can use this. I have not used it, so I can't give any advice.
如果你能以某种方式获得 VS 8 或 9 vcproj/sln,你可以使用这个. 我没有用过,所以我不能给任何建议。
If you're up to manual conversion, I would suggest something like CMake, as it's pretty easy to get ready fast enough, even for large projects.
如果您需要手动转换,我会建议使用 CMake 之类的东西,因为即使对于大型项目,它也很容易准备好足够快。
If the project has a simple layout, you could have success using Qt 4's qmake like this:
如果项目有一个简单的布局,你可以像这样使用 Qt 4 的 qmake 成功:
qmake -project
It will output a qmake .pro file, which can be converted into a makefile on many platforms (using qmake). This should work okay, but not perfectly. Alternatively, you can install the Qt plugin for VS, and let it generate the pro file from an existing VS project. It will make your build system depend on Qt4's qmake, which is probably not what you want.
它将输出一个 qmake .pro 文件,该文件可以在许多平台上转换为 makefile(使用 qmake)。这应该可以正常工作,但并不完美。或者,您可以为 VS 安装 Qt 插件,并让它从现有的 VS 项目生成 pro 文件。它会使你的构建系统依赖于 Qt4 的 qmake,这可能不是你想要的。
There are of course other things like cmake, but they will all require manual intervention.
当然还有其他的东西,比如 cmake,但它们都需要人工干预。
回答by jalf
The fastest way to do it?
最快的方法是什么?
g++ *.cpp -o myapp
Seriously, depending on your needs, even generating a makefile might be overkill. If you're just interested in a quick and dirty "let's see if we can get a working program on Linux", just throw your code files at g++ and see what happens.
说真的,根据您的需要,即使生成一个 makefile 也可能是矫枉过正。如果您只是对快速而肮脏的“让我们看看我们是否可以在 Linux 上获得一个工作程序”感兴趣,只需将您的代码文件扔到 g++ 中,看看会发生什么。