Using Caffe with CMake to create a C++ project

2,278 views
Skip to first unread message

Mohammed Ayoub NEGGAZ

unread,
Apr 19, 2016, 11:00:35 AM4/19/16
to Caffe Users
Hello,

I'm currently trying to use caffe in a school project and I'm a bit new to this.

I downloaded and installed the library without erros (with runtest).

How do I link the caffe library into a new project using cmake and create the network in C++.

Thanks in advance for you help.

Jan

unread,
Apr 21, 2016, 3:03:35 AM4/21/16
to Caffe Users
In the the CMakeLists.txt you simply import caffe using find_package(Caffe). In my case it always miraculously found the caffe files, without me giving any CAFFE_DIR params or anything like that. I don't know how cmake can know where caffe is located, but it always just worked. Then you can use the Caffe_LIBRARIES, Caffe_INCLUDE_DIRS and Caffe_DEFINITIONS variables as you would for any other library in cmake. For more info look at the header of the file yourcaffeinstallfolder/share/Caffe/CaffeConfig.cmake.

If you need an example on how to use the C++ API of caffe, look at the code of the command line utility "caffe", which is usually used for training networks: https://github.com/BVLC/caffe/blob/master/tools/caffe.cpp

Jan

Mohammed Ayoub NEGGAZ

unread,
Apr 21, 2016, 4:36:42 AM4/21/16
to Caffe Users
Thank you man.
I managed to use it manually by adding :
set(Caffe_INCLUDE_DIRS "/opt/caffe/src;/usr/include;/opt/caffe/bin/include;/usr/include/opencv;/usr/include/atlas;/opt/caffe/include")
set(Caffe_LIBRARIES "/opt/caffe/bin/lib/libcaffe.so")
to the CMakeLists file.

Chun-Hsien Lin

unread,
Apr 22, 2016, 3:13:45 AM4/22/16
to Caffe Users
Hi,

I'm also trying to manage Caffe through a C++ project. There's a recommendation that you can construct a project by Nsight (or Eclipse), It would generate the makefile automatically. Take the website below for reference.

http://tzutalin.blogspot.tw/2015/05/caffe-on-ubuntu-eclipse-cc.html

Reply all
Reply to author
Forward
0 new messages