CMake添加opencv

时间:2015-01-14 18:45:34

标签: c++ opencv cmake

我正在尝试将opencv2.4.9与cmake包含在一起:

cmake_minimum_required(VERSION 2.8.3)
project(HydroCamel)
SET(CMAKE_CXX_FLAGS "-lpthread")
find_package(catkin REQUIRED COMPONENTS
  roscpp
  rospy
  std_msgs
)
catkin_package()
set(SRC_FOLDER src/src)
set(ALOGS_FOLDER src/Algos)
set(ALOGS_UTILS_FOLDER src/Algos/Utils)
set(SRC_INCLUDE_FOLDER src/include)
set(DIRS ${SRC_FOLDER} ${ALOGS_FOLDER} ${ALOGS_UTILS_FOLDER} ${SRC_INCLUDE_FOLDER})
include_directories(${DIRS})

file(GLOB_RECURSE SRC_FILES "*.h" "*.cpp")
include_directories(include ${catkin_INCLUDE_DIRS})

set(Boost_USE_STATIC_LIBS OFF) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF) 
find_package(Boost 1.55.0 COMPONENTS filesystem system thread)
#FIND_PACKAGE(OpenCV REQUIRED core imgproc highgui)
include_directories(${OpenCV_INCLUDE_DIRS})
if(Boost_FOUND)
    include_directories(${Boost_INCLUDE_DIRS}) 
    add_executable(SourceFiles ${SRC_FILES})
    TARGET_LINK_LIBRARIES(SourceFiles ${Boost_LIBRARIES})
    TARGET_LINK_LIBRARIES(SourceFiles ${OpenCV_LIBS})
endif()

我收到此错误:

  

HydroCamel / CMakeLists.txt的CMake错误:28(find_package):找到了   包配置文件:

/home/jdorfsman/opencv-2.4.9/build/OpenCVConfig.cmake
     

但它将OpenCV_FOUND设置为FALSE,因此考虑打包“OpenCV”   没有找到。

     

- 配置不完整,发生错误!另请参阅“/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeOutput.log”。也可以看看   “/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeError.log”。

这是CMakeError.log文件:

Determining if the pthread_create exist failed with the following output:
Change Dir: /home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp

Run Build Command:/usr/bin/make "cmTryCompileExec1061744568/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec1061744568.dir/build.make CMakeFiles/cmTryCompileExec1061744568.dir/build
make[1]: Entering directory `/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec1061744568.dir/CheckSymbolExists.c.o
/usr/bin/cc    -o CMakeFiles/cmTryCompileExec1061744568.dir/CheckSymbolExists.c.o   -c /home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c
Linking C executable cmTryCompileExec1061744568
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec1061744568.dir/link.txt --verbose=1
/usr/bin/cc       CMakeFiles/cmTryCompileExec1061744568.dir/CheckSymbolExists.c.o  -o cmTryCompileExec1061744568 -rdynamic 
CMakeFiles/cmTryCompileExec1061744568.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[1]: *** [cmTryCompileExec1061744568] Error 1
make[1]: Leaving directory `/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp'
make: *** [cmTryCompileExec1061744568/fast] Error 2

File /home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp/CheckSymbolExists.c:
/* */
#include <pthread.h>

int main(int argc, char** argv)
{
  (void)argv;
#ifndef pthread_create
  return ((int*)(&pthread_create))[argc];
#else
  (void)argc;
  return 0;
#endif
}

Determining if the function pthread_create exists in the pthreads failed with the following output:
Change Dir: /home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp

Run Build Command:/usr/bin/make "cmTryCompileExec3426763052/fast"
/usr/bin/make -f CMakeFiles/cmTryCompileExec3426763052.dir/build.make CMakeFiles/cmTryCompileExec3426763052.dir/build
make[1]: Entering directory `/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp'
/usr/bin/cmake -E cmake_progress_report /home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec3426763052.dir/CheckFunctionExists.c.o
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create   -o CMakeFiles/cmTryCompileExec3426763052.dir/CheckFunctionExists.c.o   -c /usr/share/cmake-2.8/Modules/CheckFunctionExists.c
Linking C executable cmTryCompileExec3426763052
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTryCompileExec3426763052.dir/link.txt --verbose=1
/usr/bin/cc   -DCHECK_FUNCTION_EXISTS=pthread_create    CMakeFiles/cmTryCompileExec3426763052.dir/CheckFunctionExists.c.o  -o cmTryCompileExec3426763052 -rdynamic -lpthreads 
/usr/bin/ld: cannot find -lpthreads
collect2: error: ld returned 1 exit status
make[1]: *** [cmTryCompileExec3426763052] Error 1
make[1]: Leaving directory `/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp'
make: *** [cmTryCompileExec3426763052/fast] Error 2

1 个答案:

答案 0 :(得分:0)

看起来你没有指定pthread标志。

CMakeFiles/cmTryCompileExec1061744568.dir/CheckSymbolExists.c.o: In function `main':
CheckSymbolExists.c:(.text+0x16): undefined reference to `pthread_create'
collect2: error: ld returned 1 exit status
make[1]: *** [cmTryCompileExec1061744568] Error 1
make[1]: Leaving directory `/home/jdorfsman/catkin_ws/build/CMakeFiles/CMakeTmp'
make: *** [cmTryCompileExec1061744568/fast] Error 2

尝试添加:

SET(CMAKE_CXX_FLAGS "-lpthread")