There are only a few documents that explain how to use Caffe2 with C++. In this tutorial I’ll go through how to setup the properties for Caffe2 with C++ using VC++ in Windows.
1. Things you need to prepare
- Visual Studio for C++ (over VC15)
- Caffe2 Sources (from GitHub)
- Google Protocol Buffer Sources (from GitHub)
- Google Protocol Buffer Execution File for Windows (from Github)
2. Our goal
- To make a simple console program that contains Caffe2 header files by using C++
Create a new default project for a console program in VC.
Move your mouse on your project which is in the solution browser, and press Property.
On the left side of the property page, you can see the dropdown button named C/C++. Press it, then you can see subbutton named General. Press it.
On the right side of the page, there is a property named Additional Including Directory. Press the dropdown button which is on right side of the line, then press the Edit button which is below the line.
Type below directories in the textbox. In the below list, “XXX_DIRECTORY” means the name of the directory you installed program “XXX” in.
1 2 3 $CAFFE2_DIRECTORY\caffe2-master\ $CAFFE2_DIRECTORY\caffe2-master\caffe2\core $PROTOBUF_DIRECTORY\protobuf-master\src
Go to the directory “$CAFFE2_DIRECTORY\caffe2\proto”. In the directory there are some ‘.proto’ files. You should generate ‘.cc’ files and ‘.h’ files from these files using Google Protocol Buffer Execution file. Put the exe file into same directory with ‘.proto’ files, and in the prompt, execute the instruction “protoc –cpp_out=./ $FILENAME.proto”. Then you will have the new files you’ll need to execute the program.
Make a simple C++ program, including some Caffe2 headers like blob.h. If that works you can try other tutorials from here!