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上。哪条路是最快的路?autoconf吗?过时的文件吗?其他的解决方案吗?
5 个解决方案
#1
7
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个shim函数。
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.
它非常成功,我最终编写了一个OS抽象层,在许多项目中都使用这个抽象层,让我可以在Windows native、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.)
(附注:对基于c++的OS抽象层的开放源码版本感兴趣吗?)如果有足够的兴趣,我想向世界发布一个无阻碍的版本。在BOOST太大的地方(比如嵌入式项目),它最有用。
#2
3
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.
- 手动卷你的makefile。如果您拥有一组共享规则,并且拥有仅指定源文件和编译选项的最小makefile,那么这应该不会太难。
- Use GCC 4.5 as it supports more C++0x features.
- 使用GCC 4.5,因为它支持更多c++ 0x特性。
#3
2
You can export a make file from Visual Studio.
您可以从Visual Studio导出一个make文件。
Update: Actually you can't anymore, unless you have VC6 lying around
更新:实际上你不能再这样做了,除非你有VC6
#4
1
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:
如果项目有一个简单的布局,您可以使用qt4的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,但它们都需要人工干预。
#5
1
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++上,看看会发生什么。
#1
7
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个shim函数。
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.
它非常成功,我最终编写了一个OS抽象层,在许多项目中都使用这个抽象层,让我可以在Windows native、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.)
(附注:对基于c++的OS抽象层的开放源码版本感兴趣吗?)如果有足够的兴趣,我想向世界发布一个无阻碍的版本。在BOOST太大的地方(比如嵌入式项目),它最有用。
#2
3
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.
- 手动卷你的makefile。如果您拥有一组共享规则,并且拥有仅指定源文件和编译选项的最小makefile,那么这应该不会太难。
- Use GCC 4.5 as it supports more C++0x features.
- 使用GCC 4.5,因为它支持更多c++ 0x特性。
#3
2
You can export a make file from Visual Studio.
您可以从Visual Studio导出一个make文件。
Update: Actually you can't anymore, unless you have VC6 lying around
更新:实际上你不能再这样做了,除非你有VC6
#4
1
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:
如果项目有一个简单的布局,您可以使用qt4的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,但它们都需要人工干预。
#5
1
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++上,看看会发生什么。