Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to port MS Visual C++ to Linux G++

I'd like to start by saying I am a computational biophysicist, not a software engineer, so my knowledge of programming is limited to scientific computation (I use C++, Matlab, and R).

I was recently asked to port a huge package of code (~10,000 lines) to Linux from MS Visual C++, where I've been developing some code. They knew I was writing in Linux and didn't tell me until nearly a year later that they wanted it integrated with old code in Windows.

To be honest, I have no idea where to start. I was able to put together a MakeFile and compile successfully, but I get a segmentation fault, which after investigation by valgrind, is probably related to the hundreds of mismanaged memory assignments. Is there a good place for me to start that doesn't require me to learn MS Visual C++ just to get this working in Linux? Any help would be greatly appreciated. Thanks!

EDIT: Thanks for all the help so far. I'm definitely a newcomer to "real" programming so I'm not even always clear as to how I should describe my problem. Thanks for being understanding and providing some good starting points.

like image 804
Michael LeVine Avatar asked Dec 15 '22 11:12

Michael LeVine


2 Answers

I would start by turning the compiler warnings on and fixing all warnings.

-Wall -Wextra -Wstrict-aliasing -pedantic -Werror -Wunreachable-code

If you fix all the warning it will solve a lot of problems that you may never have seen. Especially when porting between different compilers (as these represents problems that will affect porting as different compilers can do different things).

When on MS compiler. Turn the warning level upto 4 and tell the compiler to treat all warnings as errors. The combination of these will get a lot of errors.

like image 185
Martin York Avatar answered Dec 24 '22 20:12

Martin York


With this codebase size, if you start by fixing random memory management issues that you are already noticing, you will soon have a working application. This assumes that you are diagnosing each segfault correctly which is not very obvious from the question. The process of learning what the new code exactly does and how will go hand in hand with the process of debugging.

If it already compiles in Linux, you should not need to learn about any other operating systems, assuming that you did not "comment out" any code that you did not understand while trying to make it work, or otherwise avoided references to Windows specific libraries that may have played a role in the application.

like image 29
Jirka Hanika Avatar answered Dec 24 '22 22:12

Jirka Hanika