https://github.com/angel-star/vscode_OpenCV_template_for_Mac/tree/master
关于OpenCV的安装我这里就不再赘述了 记得用brew并指定相关版本
在安装成功后记得注意看它的提示文字
Warning: opencv@3 dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
==> Caveats
opencv@3 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have opencv@3 first in your PATH run:
echo 'export PATH="/usr/local/opt/opencv@3/bin:$PATH"' >> ~/.zshrc
For compilers to find opencv@3 you may need to set:
export LDFLAGS="-L/usr/local/opt/opencv@3/lib"
export CPPFLAGS="-I/usr/local/opt/opencv@3/include"
For pkg-config to find opencv@3 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/opencv@3/lib/pkgconfig”
在刚刚接触这个IDE的时候,用到了code-runner这款插件,然而经过多次尝试发现它只能运行单个文件,进入到设置(defaultSettings.json)当中不难发现:它的原理也就是帮我们在shell中输入命令而达到编译运行程序的目的。
...
// Set the executor of each language.
"code-runner.executorMap": {
"javascript": "node",
"java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
"c": "cd $dir && gcc $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"objective-c": "cd $dir && gcc -framework Cocoa $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"php": "php",
"python": "python -u",
"perl": "perl",
...
}
...
但是和上篇文章MAC visual Studio Code 运行 调试c/c++ 配置(完美解决)
不同,我们的程序不光要能执行以及调试单纯的算法程序,还要适用于需要引入头文件和链接库的中型甚至大型项目,那么这时候就该请出我们的神器make
了,先不急 我们一点点看
项目目录
下面是项目的简单目录
c_cpp_properties.json
在include的过程当中如果有问题,IDE会提示你并自动生成这个文件,如果你是初学者没关系,直接在’.vscode
文件夹中创建这个文件就可以,如果是自动生成的稍作修改就可以,如果最后不行就按照我的改,我已经踩了无数的坑了,期间看过很多文章与教程,然而这是最终的版本。(当然了opencv的安装位置和编译器位置可能会不同,请各位看官自行调整,灵活一些)
小tips:
在vscode的json配置文件中如果有不清楚的标签一定要把鼠标放在上面看一看说明,下同。
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/opt/opencv@3/include",
"/usr/local/Cellar/opencv@3/3.4.5/include"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/bin/g++",
"cStandard":