OS & Software

Code::Blocks 32bit로 컴파일 하기

mainCodes 2025. 2. 2. 14:29

Code::Blocks 32bit로 컴파일 하기

2025.2.2

Code::Blocks는 C/C++ 개발을 위한 무료 오픈소스 IDE로, 여러 운영체제에서 사용할 수 있습니다. MinGW(GCC), Clang, MSVC, Intel C++ Compiler 등 다양한 컴파일러를 지원하므로 프로젝트에 컴파일러를 선택하여 적용할 수 있습니다.

 

제 경우 윈도우에 기본 설정으로 Code::Blocks를 설치해서 C 코드 예제를 빌드했는데, 64bit로 생성되었습니다. 저와 동일한 상황이라면 C 코드 예제를 빌드했을때 64bit 용 .exe가 다음과 같이 생성됩니다.

//exam1.c
#include <stdio.h>

int main() {
   int arr[5] = {10, 20, 30, 40, 50};
   int *ptr = arr;

   printf("Address of the array: %p\n", arr);
   printf("Address of the first element: %p\n", &arr[0]);
   printf("Value pointed by ptr: %d\n", *ptr);

   for(int i = 0; i < 5; i++)
       printf("Value of arr[%d]: %d, Address: %p\n", i, *(ptr + i), (ptr + i));
   return 0;
}

-------------- Build: Debug in exam1 (compiler: GNU GCC Compiler)---------------

gcc.exe -Wall -g  -c d:\study\c_lang\exam1\main.c -o obj\Debug\main.o
gcc.exe  -o bin\Debug\exam1.exe obj\Debug\main.o   
Output file is bin\Debug\exam1.exe with size 53.43 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
 
file ./exam1.exe
./exam1.exe: PE32+ executable (console) x86-64, for MS Windows  

exam1.exe
Address of the array: 000000000061FDF0
Address of the first element: 000000000061FDF0
Value pointed by ptr: 10
Value of arr[0]: 10, Address: 000000000061FDF0
Value of arr[1]: 20, Address: 000000000061FDF4
Value of arr[2]: 30, Address: 000000000061FDF8
Value of arr[3]: 40, Address: 000000000061FDFC
Value of arr[4]: 50, Address: 000000000061FE00

다음은 32bit로 .exe를 생성하기 위해 제가 적용한 방법입니다.

환경

Windows 11

1. 32비트 MinGW 컴파일러 설치

  1.1 TDM-GCC 32비트 버전 다운로드
https://jmeubank.github.io/tdm-gcc/download/

2. Code::Blocks에서 32비트 컴파일러 설정

  2.1 Code::Blocks 실행

  2.2 메뉴 → SettingsCompiler... 선택

  2.3 Selected Compiler에서 GNU GCC Compiler→Copy 버튼 선택, GNU GCC Compiler-32bit 복사

 

  2.4 Toolchain executables 탭으로 이동

        Compiler’s Installation directory를 설치한 “C:\TDM-GCC-32”로 설정 → OK

 

 

  2.5 메뉴 → ProjectBuild options... 선택

  2.6 Selected Compiler에서 GNU GCC Compiler-32bit 선택 → OK

 

여기까지 설정한 후 코드를 빌드하면 아래와 같이 기존 compiler: GNU GCC Compiler 대신 compiler: GNU GCC Compiler-32bit로 컴파일 되는 것을 확인할 수 있습니다.


-------------- Build: Debug in exam1 (compiler: GNU GCC Compiler-32bit)---------------

gcc.exe -Wall -g  -c D:\study\c_lang\exam1\main.c -o obj\Debug\main.o
gcc.exe  -o bin\Debug\exam1.exe obj\Debug\main.o   
Output file is bin\Debug\exam1.exe with size 40.76 KB
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))

 file ./exam1.exe
./exam1.exe: PE32 executable (console) Intel 80386, for MS Windows

exam1.exe
Address of the array: 0061FF04
Address of the first element: 0061FF04
Value pointed by ptr: 10
Value of arr[0]: 10, Address: 0061FF04
Value of arr[1]: 20, Address: 0061FF08
Value of arr[2]: 30, Address: 0061FF0C
Value of arr[3]: 40, Address: 0061FF10
Value of arr[4]: 50, Address: 0061FF14

EOF