VSCode c++和CMake环境搭建(for Mac OS)

Posted 木大白易

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VSCode c++和CMake环境搭建(for Mac OS)相关的知识,希望对你有一定的参考价值。

软件安装

VSCode直接去官网下载即可!

然后安装C/C++和CMake,CMake Tools插件:

编译报错

在执行cmake编译的时候报错:Bad CMake executable “”. Is it installed or settings contain the correct path (cmake.cmakePath)?

这时候需要我们去下载CMake,同样的去官网下载即可!

如何将cmake添加到命令行中:

打开cmake app,选择Tools->How toInstall For Command Line Use

随便选择一种!

然后,打开工作区的settings.json,添加下边,将环境变量设置到cmakePath中!


    // 要使用的 CMake 可执行文件的名称/路径。
	"cmake.cmakePath": "/Applications/CMake.app/Contents/bin/cmake",

再次执行Cmake Build,则成功生成Makefile!

配置task.json

	"version": "1.0.0",
	"options":
		"cwd": "$workspaceFolder/build"
	,
	"tasks" :[
		
			"type" : "shell",
			"label" : "cmake",
			"command" : "/Applications/CMake.app/Contents/bin/cmake",
			"args" : [
				".."
			]
		,
		
			"label" : "make",
			"group" : 
				"kind" : "build",
				"isDefault" : "true"
			,
			"command" : "make",
			"args" :[]
		,
		
			"label" : "Build Cmake",   //最终要执行的task
			"dependsOn":[
				"cmake",
				"make"
			]
		
	],

然后将preLaunchTask修改为Build Cmake即可!

以上是关于VSCode c++和CMake环境搭建(for Mac OS)的主要内容,如果未能解决你的问题,请参考以下文章

04-vscode搭建cmake的编译环境

win10下VSCode+CMake+Clang+GCC环境搭建

测试驱动开发 002:VSCode + CMake + Unity 环境搭建

测试驱动的嵌入式开发 002:VSCode + CMake + Unity 环境搭建

测试驱动的嵌入式开发 002:VSCode + CMake + Unity 环境搭建

测试驱动开发 001:VSCode + CMake + CppUTest 环境搭建