简体   繁体   中英

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

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, 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.

好了,您可以设置一个“ makefile项目”,并让makefile调用mingw ,但是您必须经过复杂的过程才能构建交叉编译的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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM