4

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.

Michael LeVine
  • 197
  • 1
  • 9
  • 3
    Visual Basic ain't no C++, it's a whole different language. From the rest of your question I gather you only got the names mixed up and that you actually are trying to port from MS Visual C++ to Linux but please edit your question to clarify. – syam Apr 17 '13 at 19:24
  • This question is far too vague to be useful. Is there a **specific** problem you're having trouble with? – Adam Rosenfield Apr 17 '13 at 19:24
  • There is no such thing as Visual Basic C++. There is "Visual Basic.Net" and there is "Visual C++". If your code which worked in Linux is standard C++, then it houldn't be difficult to compile and make it work in Windows using either G++ or Visual C++. By the way G++ is available in Windows also. – user93353 Apr 17 '13 at 19:25
  • Sorry, that's what I meant. As you can see, I know nothing about programming in Windows, I was legitimately just given code and told to "get it working in Linux". – Michael LeVine Apr 17 '13 at 19:25
  • @user93353: actually he's trying to port the other way around (Windows to Linux). Linux to Windows can be trivial indeed (if only through Cygwin, at worst) but Windows to Linux is a whole other matter. – syam Apr 17 '13 at 19:28
  • Updated the info, sorry for the confusion. – Michael LeVine Apr 17 '13 at 19:29
  • 2
    "I was recently asked to port to Linux from MS Visual C++", "I know nothing about programming in Windows, I was just told to 'get it working in Linux'", "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", "doesn't require me to learn MS Visual C++ just to get this working in Linux?" ... I mean this in the nicest possible way, but have you considered taking the rest of the day off and making a fresh start of things tomorrow? – Marsh Ray Apr 17 '13 at 19:29
  • 1
    Who are 'they' - the Government? – user93353 Apr 17 '13 at 19:32
  • @MichaelLeVine: 10kloc is far from huge, actually it's an extremely small project. 100x bigger (1 million lines) would barely be a mid-sized project (as far as professional programming is concerned, which I realize is not your case). What *I* would do is try to debug it (but you seem to say you lack the skills) and, if that fails, rewrite it from scratch since it's very small. – syam Apr 17 '13 at 19:33
  • "They" = advisers/bosses. – Michael LeVine Apr 17 '13 at 19:34
  • Other than looking for mismanaged memory with valgrind and gdb, what else would you suggest for debugging? – Michael LeVine Apr 17 '13 at 19:35
  • @MichaelLeVine: well valgrind and gdb pretty much cover it, but then one has to be able to understand the results and act upon. Something I do when dealing with an unknown code base is to run it through doxygen (API documentation generator) with all options enabled (referenced-by / references / etc) which helps a lot to understand the structure of the code. Maybe this can help you too? – syam Apr 17 '13 at 19:41
  • @syam Agreed, 10k lines of code is *nothing*. With a code base that small, I'd say just go through it all and write unit tests for the behaviour you expect each function/class to exhibit (assuming none exist already) and then fix the ones which don't pass. The unit tests will be a good addition anyway. – JBentley Apr 17 '13 at 19:42
  • Another useful tool in addition to Doxygen is StarUML, which is capable of reverse engineering C++ code into UML diagrams. This can give you a nice birds eye view of the code all at once. – JBentley Apr 17 '13 at 19:44
  • 2
    Thanks, these were the types of things I was looking for. 10K lines is a lot for me, most of my code is 1-2K lines so this is a pretty big project by comparison. – Michael LeVine Apr 17 '13 at 19:45
  • @JBentley oooh shiny! Didn't know about this one. Too bad it seems to be Windows-only... Someone needs to port this to Qt so we can have it on Linux too. :( – syam Apr 17 '13 at 19:47
  • @syam Ah yes, I was literally just about to comment that I noticed it's Windows only. Perhaps it would work under wine? – JBentley Apr 17 '13 at 19:47
  • @JBentley it seems to work under Wine indeed. There are a few adjustments to make as usual but nothing too complicated apparently. See http://jefferyhaynes.net/2009/12/12/getting-staruml-working-on-ubuntu-9-10/ – syam Apr 17 '13 at 19:58
  • @MichaelLeVine: just noticed your previous comment edit, well, we all went through that step at some point, the key is not to let yourself get impressed by the (apparently) sheer volume of code. When you will have tackled that, not only will you be proud of your achievement, but the next challenge you'll even think "*is it all you can throw at me?*" ;) – syam Apr 17 '13 at 20:09

2 Answers2

9

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.

Martin York
  • 257,169
  • 86
  • 333
  • 562
3

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.

Jirka Hanika
  • 13,301
  • 3
  • 46
  • 75