ubuntu下交叉編譯windows c程序


簡介

采用mingw32可以在linux下直接編譯c程序輸出為windows下的exe程序或dll鏈接庫。

個人編譯的純c程序(不含winapi),主要是c99程序,通常采用gcc/cc編譯調試后,再用mingw輸出win目標文件。

linux下目標程序及共享庫與windows下的應用程序及鏈接庫不同。

具體步驟

  1. 安裝mingw

    sudo apt-get install mingw32 mingw32-binutils mingw32-runtime

    即使不輸入mingw32-binutils和mingw32-runtime也會自動安裝

  2. 編譯

    i586-mingw32msvc-gcc hello.c -o hello.exe

  3. 個人習慣

    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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM