Sublime Text는 강력한 플러그인 생태계와 깔끔한 인터페이스로 개발자들에게 사랑받는 크로스 플랫폼 에디터입니다. 기본적으로는 텍스트 편집 기능만 제공하지만, 빌드 시스템을 구성하면 GCC 컴파일러를 직접 호출하여 C/C++ 프로그램을 작성하고 실행할 수 있습니다.
본 문서에서는 Windows, macOS, Ubuntu 세 가지 환경에서 Sublime Text를 C/C++ 개발 도구로 설정하는 방법을 설명합니다.
Windows 환경 설정
전제 조건: MinGW 설치
Sublime Text 설정 전에 먼저 GCC 컴파일러가 시스템에 설치되어 있어야 합니다. 명령 프롬프트에서
gcc -v를 실행하여 버전 정보가 표시되면 환경 구성이 완료된 것입니다.MinGW가 설치되지 않은 경우 다음 절차로 설치합니다:
- MinGW 설치 관리자를 다운로드하여 실행
- 기본 경로(C:\MinGW)에 설치
- Basic Setup의 모든 패키지 선택 후 설치
- 환경 변수 설정:
C_INCLUDEDE_PATH: C:\MinGW\includeLIBRARY_PATH: C:\MinGW\libPath에 C:\MinGW\bin 추가
C 언어 빌드 시스템 구성
메뉴에서 Tools → Build System → New Build System을 선택하여 새 설정 파일을 생성합니다. 기본 내용을 모두 삭제하고 다음 JSON을 입력합니다:
{
"cmd": ["gcc","${file}","-o", "${file_path}/${file_base_name}"],
"file_regex":"^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir":"${file_path}",
"selector": "source.c",
"encoding":"cp936",
"variants":
[
{
"name": "C_Run",
"cmd": ["cmd","/c", "gcc", "${file}", "-o", "${file_path}/${file_base_name}","&&", "cmd", "/c","${file_path}/${file_base_name}"]
},
{
"name":"C_RunInCommand",
"cmd": ["cmd","/c", "gcc", "${file}","-o","${file_path}/${file_base_name}", "&&","start", "cmd", "/c","${file_path}/${file_base_name} & pause"]
}
]
}Ctrl+S로 저장할 때 파일명을
c_compiler.sublime-build로 지정합니다(경로는 자동 지정된 위치를 사용).C++ 빌드 시스템 구성
동일한 방식으로 C++용 설정 파일을 생성합니다:
{
"cmd": ["g++","-Wall", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"encoding":"cp936",
"variants":
[
{
"name": "C++_Run",
"cmd": ["cmd", "/c", "g++", "-Wall","${file}", "-o", "${file_path}/${file_base_name}", "&&", "cmd", "/c", "${file_path}/${file_base_name}"]
},
{
"name": "C++_RunInCommand",
"cmd": ["cmd", "/c", "g++", "-Wall","${file}", "-o", "${file_path}/${file_base_name}", "&&", "start", "cmd", "/c", "${file_path}/${file_base_name} & echo.&pause"]
}
]
}저장 후 Tools → Build System에서 생성한 빌드 설정을 선택하면 실행 준비가 완료됩니다. 코드 작성 후 Tools → Build With...에서 컴파일 옵션을 선택할 수 있습니다:
- 컴파일만 수행: 오브젝트 파일 생성
- C_Run/C++_Run: Sublime Text 하단 패널에서 결과 확인
- C_RunInCommand/C++_RunInCommand: 독립적인 터미널 창에서 실행(권장)
macOS 환경 설정
macOS는 Xcode Command Line Tools를 통해 기본적으로 GCC가 제공됩니다. 터미널에서
xcode-select --install로 설치할 수 있습니다.C 언어용 설정
{
"cmd" : ["gcc -o ${file_base_name} $file_name"],
"shell" : true,
"working_dir" : "$file_path",
"selector": "source.c",
"variants" :
[{
"name" : "c_Run",
"cmd" : "./${file_base_name}"
},
{
"name": "c_RunInCommand",
"shell_cmd": "open -a Terminal.app '${file_base_name}'"
}]
}C++용 설정
{
"cmd" : ["g++ -o ${file_base_name} $file_name"],
"shell" : true,
"working_dir" : "$file_path",
"selector": "source.cpp",
"variants" :
[{
"name" : "cpp_Run",
"cmd" : "./${file_base_name}"
},
{
"name": "cpp_RunInCommand",
"shell_cmd": "open -a Terminal.app '${file_base_name}'"
}]
}macOS에서는
c_Run 또는 cpp_Run 옵션을 사용하는 것이 권장됩니다. 터미널 창을 호출하는 방식은 불필요한 시스템 메시지가 함께 출력될 수 있습니다.Ubuntu 환경 설정
Ubuntu에서는 먼저 GCC를 설치해야 합니다:
sudo apt update
sudo apt install gcc g++C 언어용 설정
{
"encoding": "utf-8",
"working_dir": "$file_path",
"shell_cmd": "gcc \"$file_name\" -o \"$file_base_name\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector": "source.c",
"variants":
[
{
"name": "c_Run",
"shell_cmd": "./${file_base_name}"
},
{
"name": "c_RunInCommand",
"shell_cmd": "gnome-terminal -x bash -c \"'${file_path}/${file_base_name}';read -p '\nPress any key to continue...'\""
}
]
}C++용 설정
{
"encoding": "utf-8",
"working_dir": "$file_path",
"shell_cmd": "g++ \"$file_name\" -o \"$file_base_name\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"selector": "source.cpp",
"variants":
[
{
"name": "cpp_Run",
"shell_cmd": "./${file_base_name}"
},
{
"name": "cpp_RunInCommand",
"shell_cmd": "gnome-terminal -x bash -c \"'${file_path}/${file_base_name}';read -p '\nPress any key to continue...'\""
}
]
}Ubuntu에서는
gnome-terminal을 통해 외부 터미널에서 프로그램을 실행하며, 실행 후 키 입력 대기 상태로 만들어 결과를 확인할 수 있도록 구성했습니다.사용 팁
- 파일 확장자: C 코드는
.c, C++ 코드는.cpp또는.cc사용 - 빠른 실행: Ctrl+B로 기본 빌드, Ctrl+Shift+B로 빌드 옵션 선택
- 인코딩 문제 발생 시
encoding값을utf-8로 변경 - 여러 소스 파일 컴파일이 필요한 경우
shell_cmd에 Makefile 호출 추가