簡介
采用mingw32可以在linux下直接編譯c程序輸出為windows下的exe程序或dll鏈接庫。
個人編譯的純c程序(不含winapi),主要是c99程序,通常采用gcc/cc編譯調試后,再用mingw輸出win目標文件。
linux下目標程序及共享庫與windows下的應用程序及鏈接庫不同。
具體步驟
-
安裝mingw
sudo apt-get install mingw32 mingw32-binutils mingw32-runtime
即使不輸入mingw32-binutils和mingw32-runtime也會自動安裝
-
編譯
i586-mingw32msvc-gcc hello.c -o hello.exe
-
個人習慣
alias cl=’i586-mingw32msvc-gcc -std=c99’
cl *.o -mdll -o test.dll
cl hello.c -o hello.exe
mingw命令
- C compiler: i586-mingw32msvc-gcc
- C++ compiler: i586-mingw32msvc-g++
- Linker for dynamic libs: i586-mingw32msvc-g++
- Linker for static libs: i586-mingw32msvc-ar
- Debugger: i586-mingw32msvc-gdb
http://hustlei.tk/2014/08/ubuntu-compile-c-for-win.html