기타

Visual Studio Code C / C++ 개발환경 설정

aim4fun 2020. 5. 10.

목차

반응형

1. VS Code 용 C / C ++ 확장을 설치한다.

Visual Studio Code C / C++ 개발환경 설정

 

2. Mingw-w64를 설치한다.

3. Mingw-w64 bin폴더의 경로를 Windows PATH 환경 변수에 추가한다.

  • 제어판 > 시스템 및 보안 > 시스템 > 고급 시스템 설정 > 환경 변수 > 시스템 변수 - Path

Visual Studio Code C / C++ 개발환경 설정

 

4. MinGW 설치 확인하기

  • gcc : C언어용 컴파일러
  • g++ : C++언어용 컴파일러
gcc --version
g++ --version

 

5. 소스 코드 작성하기

#include <stdio.h>

int main(){
    printf("Hello World");
    return 0;
}

 

6. 빌드하기

  • 컴파일러를 호출하여 소스 코드를 기반으로 실행 파일을 만든다.
  • 터미널 > 기본 빌드 작업 구성 > Others
    • 탐색기에 .vscode 폴더가 생성되고 tasks.json 파일이 추가된다.
{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "type": "shell",
      "label": "gcc.exe build active file",
      "command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\gcc.exe",
      "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}.exe"
      ],
      "options": {
        "cwd": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin"
      },
      "problemMatcher": ["$gcc"],
      "group": {
        "kind": "build",
        "isDefault": true
      }
    }
  ]
}
  • command : 실행할 파일을 위치를 작성한다.
  • cwd : 의존성 및 기타 파일을 찾기위한 현재 작업 디렉토리 위치를 작성한다.

7. 빌드 실행하기

  • 터미널 > 빌드 작업 실행
  • 탐색기에 작성한 소스 코드의 *.exe 파일이 생성된다.
  • 새 터미널 생성 후 *.exe 파일을 실행한다.

Visual Studio Code C / C++ 개발환경 설정

※ stdio.h 파일 소스를 열 수 없습니다. 오류 발생

Visual Studio Code C / C++ 개발환경 설정

💡 해결 방법

  • c_cpp_properties.json 파일 수정
  • 보기 > 명령 팔레트 > C/C++: 구성 편집(JSON)
{
  "configurations": [
    {
      "name": "Win32",
      "intelliSenseMode": "msvc-x64",
      "includePath": [
        "${workspaceFolder}/**",
        "C:/Program Files (x86)/mingw-w64/i686-8.1.0-posix-dwarf-rt_v6-rev0/mingw32/i686-w64-mingw32/include"
      ],
      "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
      "cStandard": "c11",
      "cppStandard": "c++17",
      "browse": {
        "path": ["${workspaceFolder}"],
        "limitSymbolsToIncludedHeaders": true,
        "databaseFilename": ""
      }
    }
  ],
  "version": 4
}
  • includePath : 헤더 파일이 포함 된 폴더의 위치를 작성한다.

 

🍀 참고 사이트

'기타' 카테고리의 다른 글

Window, BOM, DOM  (0) 2020.06.24
URI와 URL 그리고 URN  (0) 2020.06.10
sdkman JDK 경로 Oracle SQL Developer에 설정하기  (0) 2020.05.20
JUnit 5 vs JUnit 4  (0) 2020.05.16
vscode 터미널 한글 깨짐 문제 해결 방법  (0) 2020.05.11

댓글