개발

visual studio code c++ setting on mac

내공얌냠 2022. 2. 10. 12:10

거두절미하고, 이상하게 또 실행이 안되었다.

https://velog.io/@cookncoding/VS-Code%EC%97%90-C-%EA%B0%9C%EB%B0%9C-%ED%99%98%EA%B2%BD-%EC%84%B8%ED%8C%85%ED%95%98%EA%B8%B0

 

VS Code에 C/C++ 개발 환경 세팅하기

이번에 동기들과 Algorithm Study를 진행하기로 했다.📚원래는 window 환경에서 알고리즘 문제를 풀었어서 Visual Studio를 사용했었다.Mac에서는 Xcode를 쓰려고했다. 하지만 이번에 Python이랑 C++ 2가지 언

velog.io

위 링크로 다시 설정하니 잘 되었다.

아래는 그저 참고용으로만..

 

세팅할 때마다 조금 고생을 하거나 엎어버려서 잘 되었을 때 기록해보기로 한다.

세 가지 설정 파일을 만들고, code-runner 설정을 해주면 된다.

팔레트 사용은 반복되는 부분이라 미리 적어놓았다.

command + shift + p : 팔레트

먼저 extensions 에서 c/c++ 과 code-runner 설치!

좌측 맨 아래 블록이 있는 것 같은 부분이 extension 설치하는 부분이고,

c/c++ 검색하면 나오는 c/c++, c/c++ extension pack, themes, code runner .. 다운로드하기!

task.json 

terminal > configure default build task... > c/c++ : c++ lang build active file

하면 .vscode 폴더 내에 task.json 파일이 생성된다.

아래 구문과 비교하여 필요한 부분을 넣자.

std=c++17, stdlib=libc++ 이 부분이 중요하다. 빼먹지 말고 넣자.

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "cppbuild",
			"label": "C/C++: clang++ build active file",
			"command": "/usr/bin/clang++",
			"args": [
				"-std=c++17",
				"-stdlib=libc++",
				"-fdiagnostics-color=always",
				"-g",
				"${file}",
				"-o",
				"${fileDirname}/${fileBasenameNoExtension}.o"
			],
			"options": {
				"cwd": "${fileDirname}"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "compiler: /usr/bin/clang++"
		}
	]
}

 

settings.json

팔레트 + open setting 타이핑을 치면 아래 이미지와 같이 나온다.

(JSON) 부분을 선택한다.

code-runner.executorMap 부분의 cpp 에서 clang++ -std=c++17 이 부분을 추가한다.

code-runner.runInTerminal : true 는 터미널에서 실행하는지 물어보는 부분이므로 기본 설정으로 체크가 되어있지만

안되어있다면 체크하는 게 좋다. (이렇게 json 말고도 ui로도 설정할 수 있다.)

{
    "code-runner.runInTerminal": true,
    "grunt.autoDetect": "on",
    "code-runner.executorMap": {
    ...
    
        "cpp": "cd $dir && clang++ -std=c++17 $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
    ...
    
     }
}

 

c_cpp_properties.json

팔레트 + c/c++ : edit configuration(JSON) 선택

필요한 부분만 넣는다.

defines 에 넣은 것들은 한글 깨짐을 방지하기 위함이라고 한다.

cStandard, cppStandard 부분 참고하면 된다!

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": ["_DEBUG", "UNICODE", "_UNICODE"],
            "macFrameworkPath": [],
            "compilerPath": "/usr/bin/clang++",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "macos-gcc-arm64"
        }
    ],
    "version": 4
}

 

References

https://code.visualstudio.com/docs/cpp/config-wsl

https://torbjorn.tistory.com/658

 

[VSCode] Mac에서 vscode C++ 개발환경 구축

맥 visual studio로는 C++ 개발을 할 수 없습니다. 닷넷밖에 못합니다. 좀 거지같습니다. 꿩대신 닭으로 vscode로 C++ 개발환경을 세팅해보겠습니다. 맥 vscode C++ 세팅 방법 먼저 clang, lldb가 설치되어 있

torbjorn.tistory.com

 

728x90
반응형