rrforshort
rrforshort

Reputation: 11

Porting from Visual C++ to Linux

I'm a bit new to this so apologies if this doesn't make sense/ is a stupid question!!

Anyway, I'm creating a project that has to uses OpenCV as well as UDP sockets. I'm currently writing the C++ part in Visual Studio (2013), so the project is visual C++. The plan is eventually to move the project from a PC on to an embedded computer running some linux distro.

I'm wondering if there will be any majors issues later on that will cause me headaches if I develop the whole C++ code on Visual Studio and then try to port to a linux environment?

Also if that is the case would there be a way to avoid these future problems by just changing IDE or something else??

Upvotes: 1

Views: 5457

Answers (4)

Benilda Key
Benilda Key

Reputation: 3102

It is possible to have a project that compiles using Visual Studio on Windows that also compiles on Linux. I have two such projects. They may be found at https://svn.sullivanandkey.com/SnKOpen/cpp/now/trunk/ and https://svn.sullivanandkey.com/SnKOpen/cpp/yekneb/trunk/.

Neither of these projects use a GUI, however it is possible if you use a cross platform GUI library such as wxWidgets, FLTK, or Qt.

My YekNeb project compiles on the following operating systems: FreeBSD, GNU/Linux, Microsoft Windows, Solaris, and ReactOS.

The key is to limit yourself to APIs that are available on all the platforms you wish to target. If you use any third party libraries such as OpenCV, make certain they are supported on every platform you wish to use.

At times you need to use code that behaves differently depending on whether or not a given function is available on a given platform. I recommend against using the techniques I used in the two projects I mentioned above to do that. I will soon be transitioning to CMake and making use of the configure functionality found at CMake:How To Write Platform Checks.

I hope this helps.

Upvotes: 0

jpo38
jpo38

Reputation: 21594

If you are using MFC for your GUI you can say goodbye to any possibility to port your code to Linux one day.

If you are using visual studio only as an IDE and use portable third party libraries (Qt, boost...) you should be able to port the code smoothly.

One good way to achieve this:

  • Have all your file names in lower case
  • Avoid using any win32 API (prefer boost library)
  • As mentioned above, don't use \ in file paths, / almost always works on all platforms
  • Write some Cmake scripts to generate your vcproj and sln files
  • ... it is not exhaustive...

If this works on PC, you can then use Cmake to generate Linux Makefiles and it will hopefully compile and run under Linux.

Ideally, have lots of unit tests to be ran, because porting may introduce multiple small bugs that you will have a hard time finding.

Upvotes: 1

Steean
Steean

Reputation: 83

I have recently moved a Visual C++ project to a Linux distro without major troubles. The biggest problem was properly that I had to change all \ to /. If you are in doubt you could always use a multiplatform compiler.

Upvotes: 0

jd6
jd6

Reputation: 429

You can use a multiplatform compiler, like MINGW (http://www.mingw.org/) with eventually Codeblocks (http://www.codeblocks.org/) or Netbeans to prevent the compatibility issues. The written code should be highly compatible. But with the Visual-C++ compiler, it is probably more complicated to compile on Linux the program because this compiler is only on Windows.

Upvotes: 0

Related Questions