STUDY
Tiny C Compiler + vscode 본문
Visual Studio Code라는 Text Editor로 C 언어 프로그램을 만드려면, compiler가 필요하다. 대표적인 것이 GNU gcc, clang 등이 있다. 그런데 Windows 10에서 c compiler를 사용하기 위해서는 꽤나 번거로운 과정을 거쳐야 한다. (a) cygwin을 설치하고 gcc, g++, gdb, make 등을 설치된 cygwin 환경 위에 다시 설치, (b) MSYS2를 설치하고 update를 하고 pacman으로 필요한 tool chain을 설치, (c) tdm-gcc를 설치, (d) docker를 실행하고 linux 환경에서 gcc 설치 등이다. 그런데 단지 C 언어만 다룬다면 이런 과정이 전혀 필요없다. TCC라는 것을 사용하면 된다. 번거롭게 C compiler를 사용하기 위해 먼저 cygwin이나 MSYS2 등을 설치하여 리눅스 환경을 흉내낼 이유도 없다. 설치할 필요도 없다. 더 좋은 것은 굉장히 빠르다. Vscode가 설치되었다면, 다음과 같이 설정만 해주면 끝이다.
1. Download `Tiney C Compiler` and unzip it where you want.
2. Add path to system variables.
3. Edit `c_cpp_properties.json` file in vscode command tool
- Press `Ctrl+Shift+P` to open the Command Palette.
- Edit `Code Runner` configurations (JSON)
{
"configurations": [
{
"name": "Win32_TCC",
"includePath": ["D:/util/tcc/include"],
"compilerPath": "D:/util/tcc/tcc",
"defines": ["_DEBUG", "UNICODE", "_UNICODE"],
"intelliSenseMode": "${default}",
"cStandard": "c11",
"cppStandard": "c++20"
}
],
"version": 4
}
- Edit `Code Runner` configurations
{
"workbench.colorTheme": "Solarized Dark+",
"code-runner.runInTerminal": true,
"editor.fontFamily": "'Ubuntu mono', Consolas, 'Courier New', monospace",
"editor.formatOnSave": true,
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.cppStandard": "c++20",
"editor.tabSize": 2,
"[python]": {
"editor.tabSize": 4,
},
"editor.fontSize": 20,
"terminal.integrated.fontSize": 20,
"code-runner.executorMap": {
/* for GNU gcc compiler */
// "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
// "c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt && rm *.exe",
/* for tcc compiler */
// "c": "cd $dir && tcc $fileName -o $fileNameWithoutExt.exe && $dir$fileNameWithoutExt.exe",
"c": "cd $dir && tcc -run $fileName",
"cpp": "cd $dir && g++ -std=c++2a -fconcepts $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt && rm *.exe",
/* for Rust compiler */
"rust": "cd $dir && rustc $fileName && $dir$fileNameWithoutExt && rm *.pdb && rm *.exe",
},
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
}
이렇게 해놓고 `Code Runner`의 Ctrl+Alt+n`으로 바로 결과물을 확인할 수 있다.
매우 빠르다. 왜 진작 TCC를 사용하지 않았는지 모르겠다.
'c' 카테고리의 다른 글
raylib: GUI programming library (0) | 2020.02.18 |
---|---|
MSYS2 `pacman -Syu` error (0) | 2020.02.18 |
Installing C Compilers in Windows (0) | 2019.12.02 |
while(!feof(FILE *fp)) (0) | 2019.06.06 |
How to use gcc in Windows 10 (0) | 2019.03.26 |