![d77e9b926014c9ea581423ce339b8f74.png](https://i-blog.csdnimg.cn/blog_migrate/9512a9a7fc80b0e9831279a1f8384fc8.jpeg)
- 电脑配置
- 1. ubuntu 16.04 LTS+Caffe 1.0.0+Vscond 1.43.2
- 2 anaconda 3
- 3 caffe 安装目录为 ~/.conda/envs/caffe/caffe
- 在cd ~/.conda/envs/caffe
- mkdir cfproj
- 打开vscode, 选择打开刚刚创建好的cfproj文件夹
- 编写一个简单的测试程序,保存为blob_demo.cpp
- #include <vector>
#include <iostream>
#include <caffe/blob.hpp>
using namespace caffe;
using namespace std;
int main(void)
{
Blob<float> a;
cout<<"Size : "<< a.shape_string()<<endl;
a.Reshape(1, 2, 3, 4);
cout<<"Size : "<< a.shape_string()<<endl;
float *p = a.mutable_cpu_data();
for(int i = 0; i < a.count(); i++)
{
p[i] = i;
}
for(int u = 0; u < a.num(); u++)
{
for(int v = 0; v < a.channels(); v++)
{
for(int w = 0; w < a.height(); w++)
{
for(int x = 0; x < a.width(); x++)
{
cout<< "a[" << u << " " << v << " " << w << " " << x << "]=" << a.data_at(u,v,w,x) << endl;
}
}
}
}
cout << "ASUM=" << a.asum_data() << endl;
cout << "SUMSQ = "<<a.sumsq_data() << endl;
return 0;
} - 如下图所示
![058c98fb3e261f4ec29a3e2d54258a26.png](https://i-blog.csdnimg.cn/blog_migrate/fd34c6d904e51976a7880d8fb7e6c06f.jpeg)
8. 选择Terminal/Configure Tasks 设置编译参数,选择g++ build active file.
![6fd12ab2eba7fceb2c908f00e7d0491a.png](https://i-blog.csdnimg.cn/blog_migrate/f5ff407e6ba9be830793ccdcd3b086bf.jpeg)
自动创建了task.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": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"${file}",
"-I/home/robin/.conda/envs/caffe/caffe/include/",
"-D",
"CPU_ONLY",
"-I/home/robin/.conda/envs/caffe/caffe/.build_release/src/",
"-L/home/robin/.conda/envs/caffe/caffe/build/lib/",
"-lcaffe",
"-lglog",
],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
9. 设置运行/调试参数,选择Run/Add configurations... , 在下拉菜单选择c/c++ GDB launch.
修改红色部分内容如下
![40b2b849742fa0a89601894672791f99.png](https://i-blog.csdnimg.cn/blog_migrate/358d81e08c60169a672f092189d9fd7e.jpeg)
10. 设置编译器包含路径
在vscode界面同时按住shift+ctrl+p 出现选择界面,请选择C/C++:Edit configurations(UI)
![c2acc97a068bf8bcde55a3aaa2206f52.png](https://i-blog.csdnimg.cn/blog_migrate/3acea813360a847a47954237085d9805.jpeg)
11. 执行build and run在还需要在vscode terminal执行如下命令
export LD_LIBRARY_PATH=../caffe/build/lib/:$LD_LIBRARY_PATH
否则将出现如下错误
error while loading shared libraries: libcaffe.so.1.0.0
![8ae5a97293bcd38f0cf5f6e8ac3bee91.png](https://i-blog.csdnimg.cn/blog_migrate/90542787b84e3335d409d84be4ff63ce.png)
13. 按快捷键F5, 开始进入调试,设置你在哪里停住的断点,如果出现如下界面,说明调试成功了,恭喜!
![cd1652f37ed8d6fbaf1d4e985475481d.png](https://i-blog.csdnimg.cn/blog_migrate/8a4f47569785e002c6455b992d3ce918.jpeg)