开发者

Port Visual Studio C++ to Linux

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!).

I now wanna port it开发者_StackOverflow社区 to Linux. Which way is the quickest way to do it? autoconf? old-fashioned make file? any other solution?


I would use regular make but keep it simple with default rules as much as possible. Add in dependencies as you go along.

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.

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.

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.

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.

(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.)


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.

  1. 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.
  2. Use GCC 4.5 as it supports more C++0x features.


You can export a make file from Visual Studio.

Update: Actually you can't anymore, unless you have VC6 lying around


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.

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.

If the project has a simple layout, you could have success using Qt 4's qmake like this:

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.

There are of course other things like cmake, but they will all require manual intervention.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜