1

I am a beginner with Caffe library. I was just compiling and test code in this tutorial example: https://github.com/DeepLearningStudy/caffe/blob/master/examples/ex4_layer/main.cpp . I have a CPU_ONLY build, so compiling gives out error undefined reference to `void caffe::caffe_gpu_dot(int, double const*, double const*, double*)' . Issued by calling the function Forward(). In order to complete compilation I modified argmax layer code and put forward_cpu() as public function member.

Despite there is the line: Caffe::set_mode(Caffe::CPU) seems like forward function calls for gpu method.

Here is my CMakeLists.txt : cmake_minimum_required(VERSION 2.8.8)

project (hellocaffe)

if(ON) if(NOT OpenCV_FOUND) set(Caffe_OpenCV_CONFIG_PATH "/usr/share/OpenCV") if(Caffe_OpenCV_CONFIG_PATH) get_filename_component(Caffe_OpenCV_CONFIG_PATH ${Caffe_OpenCV_CONFIG_PATH} ABSOLUTE)

  if(EXISTS ${Caffe_OpenCV_CONFIG_PATH} AND NOT TARGET opencv_core)
    message(STATUS "Caffe: using OpenCV config from ${Caffe_OpenCV_CONFIG_PATH}")
    include(${Caffe_OpenCV_CONFIG_PATH}/OpenCVModules.cmake) 
  endif()

else()
  find_package(OpenCV REQUIRED)
endif()
unset(Caffe_OpenCV_CONFIG_PATH)

endif() endif()

Compute paths

get_filename_component(Caffe_CMAKE_DIR "/home/nikfio/bin/caffe/cmake" PATH)

FIND_PACKAGE(Caffe)

set(Caffe_INCLUDE_DIRS /home/nikfio/bin/caffe/include) list(APPEND Caffe_INCLUDE_DIRS "/usr/include") list(APPEND Caffe_INCLUDE_DIRS "/usr/local/cuda-9.0/include") list(APPEND Caffe_INCLUDE_DIRS "/usr/include/opencv") list(APPEND Caffe_INCLUDE_DIRS "/usr/include/atlas") list(APPEND Caffe_INCLUDE_DIRS "/home/nikfio/bin/caffe/build/src/")

include_directories(${Caffe_INCLUDE_DIRS})

Definitions

set(Caffe_DEFINITIONS "-DUSE_OPENCV;-DUSE_LMDB;-DUSE_LEVELDB")

set(CAFFE_DIR /home/nikfio/bin/caffe)

set(LIBRARY -L${CAFFE_DIR}/build/lib -L/usr/local/Cellar/opencv/2.4.11_1/lib/ -lglog -lprotobuf -lpython2.7 -lcaffe -lm -lpthread -lopencv_core -lopencv_imgproc -lopencv_highgui)

add_executable(ex_logreg_mnist ex_logreg_mnist.cpp)

target_link_libraries(ex_logreg_mnist ${LIBRARY} -lboost_system)

Does someone know why or have a better solution?

Regards

Miki
  • 40,887
  • 13
  • 123
  • 202
nikfio
  • 21
  • 3
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Nov 02 '17 at 17:55

1 Answers1

1

Add to your definitions line the following:

set(Caffe_DEFINITIONS "-DUSE_OPENCV;-DUSE_LMDB;-DUSE_LEVELDB;-DCPU_ONLY=1")

CPU_ONLY=1 should comment-out all GPU code correctly.

rkellerm
  • 5,362
  • 8
  • 58
  • 95