开发者

Coding Linux console application in Visual C++ 2008/2010 Express

开发者 https://www.devze.com 2022-12-16 23:24 出处:网络
I was told about the fascination of C++ and I have recently downloaded Visual C++ IDE to start learning C++.

I was told about the fascination of C++ and I have recently downloaded Visual C++ IDE to start learning C++.

However I had this question in mind: How can I write C++ console application in Visual C++ and build it for Linux and Windows? Is there any plugin, 开发者_Python百科additional compilers or hacks to go around with?


The most important thing is you want to avoid OS specific calls and stick with the standard C++ library.

If you don't include any Windows header file such as windows.h or winuser.h, then the compiler will warn you if you try to call a Windows specific function.

There are some features available on both Windows and Linux that need to be handled slightly differently (such as networking and memory mapping). You may want to look into a portable runtime library such as the Apache Portable Runtime that will abstract out the differences for you.


Well, you can set up a 'makefile project' and have the makefile invoke mingw, but you'd have to go though the complex procedure to build a cross-compiling ming.


If you stick to standard C++, you can compile the same source in linux with gcc.

You can also try your luck with Wine.


I would recommend using Visual C++ just as a project manager and text editor, and possibly for compiling for Windows. Then in your project maintain a Makefile to use with a cross-compiling GCC to produce the Linux binaries. Here is some information on setting up GCC on windows to cross-compile for Linux.

Do not expect this to be easy, but it's doable.


Writing portable code doesn't mean you can actually build all targets from a single environment. It's probably possible, if you like a lot of pain and hassles for no great reward, but the sane way to do it would be to just have a Linux machine sitting nearby (or in a VMware virtual machine on the same computer). Then a quick login to the Linux box, download the latest source, compile, test, and then go home and watch Futurama instead of sitting up all night trying to figure out how to work a cross-compiler that basically nobody else uses.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号