Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 to Linux. Which way is the quickest way to do it? autoconf? old-fashioned make file? any other solution?

like image 698
MBZ Avatar asked Jul 21 '10 09:07

MBZ


4 Answers

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

like image 107
Amardeep AC9MF Avatar answered Oct 21 '22 01:10

Amardeep AC9MF


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.
like image 28
Alex B Avatar answered Oct 21 '22 02:10

Alex B


You can export a make file from Visual Studio.

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

like image 2
graham.reeds Avatar answered Oct 21 '22 00:10

graham.reeds


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.

like image 1
rubenvb Avatar answered Oct 21 '22 01:10

rubenvb