If you want to create custom files in caffe, there are two ways:
Easy way
- Make the necessary changes and save the file (in your case - classic.cpp) inside the directory (say, test) in the examples folder in th e caffe root.
- run
make . This will automatically add the necessary cxxflags and ldflags and compile your code and put the executable in the build / examples / test folder. This also ensures that the CPU_ONLY flag is set (as indicated in Makefile.config)
Hard way
- Run make without the print option (mentioned in Makefile.config). You can see the compilation options and links used to create examples and tools. You can copy and paste these parameters (and make the necessary changes to the relative paths, if used) to compile your file.
Hope this helps
Edit Because operators requested a simple way, this can be done as follows.
This is a very minimal example , and I recommend the OP refer to the complete online documentation and cmake usage example.
- Requirements
- Caffe needs to be built with cmake . Relatively easy, as the current main branch has CMakeLists and everything that is defined. Use Cmake-gui or ccmake to configure your options.
Now I assume that you have a project structure as follows.
-project - src - class1.cpp - CMakeLists.txt ( to be added ) - include - class1.hpp - main.cpp - CMakeLists.txt ( to be added )
CMakeLists.txt (src) should contain (at least) the following lines,
cmake_minimum_required(VERSION 2.8) find_package(OpenCV REQUIRED) # Optional in case of dependency on opencv add_library( c1 class1.cpp )
Note. In case class1 depends on other external libraries, the path to the headers should be included using include_directories .
CMakeLists.txt (external) must contain a minimum minimum
cmake_minimum_required(VERSION 2.8) PROJECT(MyProject) find_package(OpenCV REQUIRED) find_package(Caffe REQUIRED) include_directories( "${PROJECT_SOURCE_DIR}/include" ) add_subdirectory( src ) include_directories( "$Caffe_INCLUDE_DIRS}" ) add_executable(MyProject main.cpp) target_link_libraries( MyProject ${OpenCV_LIBS} c1 ${Caffe_LIBRARIES} )
Now the following commands from the project directory will create the MyProject executable file inside the build folder.
mkdir build cd build cmake .. make
Then you can run your program with ./MyProject (arguments)
EDIT 2
Meeting the need for making coffee with CMake is very important for this. You need to configure and generate a Makefile using CMake. To do this, use cmake-gui or ccmake so you can set options like CPU_ONLY, etc.
You must create the build directory inside caffe and do the following for a basic installation
mkdir build cd build cmake .. make -jX
Now the .cmake directory in the $ HOME folder consists of the following /home/user/.cmake/packages/Caffe/<random_string> . This file points to the installation location of caffe (which is our build directory)
The find_package command should now work without errors for your other projects. And since you use CMake, you can save your project folder outside the Caffe folder (and it's better to leave it outside, because the make caffe process will try to create your files, but it will fail).
Note If the error persists, you can manually set Caffe_DIR during cmake configuration.