0

Say I have a open source C::B C++ (non-C++11, perfectly compatible with the 1998 ISO standard) project I've downloaded which is using MinGW/GCC (TDM-1 4.7.1 or 4.7.2 - doesn't work with newest version),; can I port the source files from it to Visual Studio 2010 and be able to make it work without massive code rewriting? Or there are certain cases in which it won't be possible? Or it depends on various things?

EDIT: The code relies on additional external utilities and libraries such as:

  • Lua
  • SDL 2.0 + SDL Image 2.0
  • OpenGL
Banderi
  • 656
  • 3
  • 7
  • 29

4 Answers4

2

If the project was written using portable C++98 code you shouldn't have too much trouble. First, I would check you can compile in GCC with -std=c++98 -pedantic flags and fix any warnings to ensure you are not relying on any GCC extensions.

It also depends on the portability of any required libraries.

Chris Drew
  • 14,926
  • 3
  • 34
  • 54
2

The most General and correct response is: It depends on various things.

What kind of project are you refering to? Is it wxWidget, QT4, GTK+, OpenGL? How much do you use c++11?

Assuming that we are talking about a simple Console Application the easiest way to verify whether you can migrate to MSVC2010 is to switch compiler inside Code::Blocks project.

Select Project->Build Option... and under Selected compiler choose Microsoft Visual Studio C++ 2010. Afterwards try to recompile. The warning and errors will show you how easy will be the porting.

Of course you have to install Code::Blocks with MSVC2010 too.

EDIT: The OpenGL library is supported by MSVC2010 and libsdl has VC development libraries. However, things seem to be more complex with Lua. My guess is that you might start a substantial porting work here.

ztik
  • 3,482
  • 16
  • 34
  • No C++11 is used, standard 1998 ISO compilation is perfectly fine, MSVC2010 compilation stops with `invalid numeric argument '/Wno-sign-compare'`. EDIT: I've added the libraries used. – Banderi Dec 23 '14 at 14:07
  • @Banderi: If you have a specific problem with a specific piece of code with a specific compiler, construct a [minimal testcase](http://sscce.org) that demonstrates the issue and ask a specific question about it. – Lightness Races in Orbit Dec 23 '14 at 14:14
  • 1
    @Banderi the `/Wno-sign-compare` is not important and can be switched off. Also edited response for libraries. – ztik Dec 23 '14 at 14:25
  • Mmmm. Well that sounds pretty bad. I'll try to import the files again in VS2010, if I encounter any major problems I'll possibly open new questions, thank you. – Banderi Dec 23 '14 at 14:29
2

Try it!

If your code is standard-compliant and does not rely on any GCC extensions or GCC-specific libraries, then you should be fine out-of-the-box.

Note though that different compilers support C++ in different ways; for example, even Visual Studio 2013 has only passing C++11 support so if your program is a C++11 program with things like ranged-for and initializer lists in it then, depending on the version you're using, it's just not going to work without those pieces of code being rewritten to look more like C++03.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
  • No C++11 is involved. Is there a way to check for GCC-specific extensions/libraries the project might be relying on without manually scanning through the code? – Banderi Dec 23 '14 at 14:10
  • 1
    @Banderi: Open your code in Microsoft Visual Studio and attempt to build it. You'll very quickly discover whether there are problems. – Lightness Races in Orbit Dec 23 '14 at 14:12
  • That actually is the first thing I tried to do... it didn't go very well. I might have done it the wrong way tho. I've created a "New project from existing code", but maybe there are settings I overlooked, or it's simply non as easy, that's why I've asked. Is there a "right" way to do it? Or do you want me to describe the major problems VS is giving me? Tho it might sound a bit OT-going, if so I'll open a new question for major ones. – Banderi Dec 23 '14 at 14:18
0

I actually made a mistake: C::B indeed told me there were multiple errors in the compilation attempt with the MSVC2010 compiler, because the code included many Unix-only libraries, too intricately so to be easily avoided. Thus, I'm thinking of either making MinGW/GCC work in Visual Studio itself or sticking with C::B.

(Continues here: POSIX Headers (from MinGW project) in Visual Studio 2013)

Community
  • 1
  • 1
Banderi
  • 656
  • 3
  • 7
  • 29