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

强颜欢笑 提交于 2020-01-01 06:36:51

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/16068415/need-to-port-ms-visual-c-to-linux-g

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!