Linux

Cross compile for windows in linux

GunwooYun 2025. 9. 10. 17:43

Corss compile

Toolchain

 

for 32bit

  • i686-w64-mingw32-gcc
  • i686-w64-mingw32-ar

for 64bit

  • x86_64-w64-mingw32-gcc
  • x86_64-w64-mingw32-ar

 

32bit windows target 예 )

hello.h

#ifndef _HELLO_H_
#define _HELLO_H_
extern void hello();
#endif
 

hello.c

#include "hello.h"
#include <stdio.h>

void hello()
{
   printf("hello, world\n");
}

 

오브젝트 파일 생성

$ i686-w64-mingw32-gcc -c hello.c -o hello.o

$ i686-w64-mingw32-gcc -c hello.c -o hello.o

정적 라이브러리 생성

$ i686-w64-mingw32-ar rscv libhello.a hello.o

 

테스트 (gcc version: gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 7.3.0)