Compile Windows C console applications in Linux
Can I compile a Windows C console application (.exe) in Linux? (more specific, Ubuntu)
I heard a long time ago of cross-c开发者_如何学编程ompilers, but I wasn't interested in them at that time.
Best regards
There is this post which gives some info, as well as this duplicate question
As you are using Ubuntu, the packages you need is (I think) mingw32
apt-get install mingw32
Then compile with i586-mingw32msvc-gcc, e.g.
i586-mingw32msvc-gcc helloworld.c -o helloworld.exe
You can if it's standard C, and doesn't use Windows libraries.
C code itself is very portable, and the standard C libraries (libc) are available pretty much everywhere. If your code does printf() and sscanf() and fopen() and so on, then it will just compile and run on another platform. Windows, Linux, BSD, etc.
It's the libraries other than libc that introduce portability challenges.
Anything that links with Windows-specific platform libraries is trouble. Kernel32.lib, user32.lib, etc etc.
There are third-party libs, too, that, if written in C, should be available across Linux and Windows. PCRE is a good example here - it's a Regular Expression library written in C, and it's available on Windows as well as on Linux. there are literally hundreds of libraries in this set.
If you confine yourself to libc and library calls into portable libs, then you will have a portable C application.
If you're talking about a strictly ANSI C application, then you shouldn't have any problem compiling with gcc on a Linux platform.
If you're liking in to Windows System libraries, you're hosed and would have to replace those calls with their *nix System equivelants (if there are any).
If your looking to compile a program from Linux into a Windows executable, yes cross compilers would be an option. http://www.airs.com/ian/configure/configure_5.html helped me a bit.
Do you mean can you build a windows .exe on Linux (ie develop on linux and deliver the app to Windows users?)
Or do you mean take a Windows app and recompile (port) it to Linux so it's built and runs on Linux?
You can use WINE and install VS for example .Other solution use MonoDevelop.
also you cans use cross compilers like Code::Blocks
Cross compiling is possible. AFAIK you get a windows executable, which of course will run under windows (and possibly WINE).
There are 2 possible choices for that: mingw and cygwin.
One tutorial here. MingW cross compile page is here.
You can also use standard gcc in terminal of linux , you can use same programs you need only to change the std.h with unistd.h (meaning you will need to change to linux specific libraries). I have a course about linux programming at school it except it's on ubuntu and library changes for input/output and some thread related linux specific ,all it's the same
example : gcc -c myprogram.c // to compile gcc -o myprogram.o name to make lib myprogram // with arguments if there are any
精彩评论