【问题标题】:error with compilation (aruco library)编译错误(aruco 库)
【发布时间】:2015-10-22 23:05:23
【问题描述】:

我在尝试编译包时遇到此错误。 这是我遇到错误的 CMAKE:

    cmake_minimum_required(VERSION 2.8.3)
project(aruco_marker_detector)

## Find catkin macros and libraries
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
## is used, also find other catkin packages
find_package(catkin REQUIRED COMPONENTS
  cv_bridge
  geometry_msgs
  image_transport
  roscpp
  std_msgs
  tf
  tf_conversions
  uvc_camera
)

## System dependencies are found with CMake's conventions
# find_package(Boost REQUIRED COMPONENTS system)

##############################################################################
# OpenCV
##############################################################################
find_package(OpenCV REQUIRED)

##############################################################################
# Eigen
##############################################################################
find_package(Eigen REQUIRED)
add_definitions(${EIGEN_DEFINITIONS})

##############################################################################
# AruCo
##############################################################################
find_package(aruco REQUIRED )

错误是关于Aruco,系统找不到库!!

我现在真的不知道如何解决它。 我已按照本网站“http://maztories.blogspot.com.es/2013/07/installing-aruco-augmented-reality.html”中的说明安装了 aruco 1.2.4。

【问题讨论】:

  • 你看到that question了吗?它的作者说它在设置变量 CMAKE_MODULE_PATH 后可以工作。
  • 我现在看到了,所以你建议在 CMAKE 中添加这一行 set(CMAKE_MODULE_PATH /usr/local/lib/cmake) 或者答案,比如使用这个设置名为 CMAKE_PREFIX_PATH 的 CMAKE 变量: cmake -D CMAKE_PREFIX_PATH=/usr/local/lib ????
  • 像往常一样:如果您希望仅在单台 PC 上构建项目,您可以在 CMakeLists.txt 文件中设置所有变量。如果你想在多台机器上构建你的项目,最好不要更改CMakeLists.txt,而是将变量定义传递给cmake调用。
  • 第二种方法肯定是最好的,但我如何将变量定义传递给 cmake 调用?很抱歉我几个月以来一直在使用 ubuntu,我遇到了这类员工的问题。在我的具体情况下,如果我想使用最通用的解决方案,我应该怎么做?
  • 我的意思是cmake -DCMAKE_PREFIX_PATH=/usr/local/lib <path-to-source-dir>。它实际上将CMAKE_PREFIX_PATH 变量定义传递给cmake。

标签: cmake aruco


【解决方案1】:

如果你已经正确配置了 OpenCV,你可以自己生成 ArUco 的 lib:

# latest aruco version available at: http://sourceforge.net/projects/aruco/files/
# also, aruco is now part of OpenCV: http://docs.opencv.org/master/d9/d6d/tutorial_table_of_content_aruco.html
# here I'm demonstrating the usage of v1.2.5

# useful definitions
set(ARUCO_DIR     "/PATH/TO/aruco-1.2.5")
set(ARUCO_INCLUDE "${ARUCO_DIR}/include")
set(ARUCO_SRC     "${ARUCO_DIR}/src")
set(ARUCO_LIB      aruco-1.2.5)

# find the source files
file(GLOB hdrs "${ARUCO_INCLUDE}/aruco/*.h*")
file(GLOB srcs "${ARUCO_SRC}/*.c*")

# create aruco's cmake target
add_library(${ARUCO_LIB} STATIC "${hdrs}" "${srcs}")

# link aruco against OpenCV
find_package(OpenCV REQUIRED)
include_directories(SYSTEM "${OpenCV_INCLUDE_DIRS}" ${OpenCV_LIBS})


# use aruco in your project
# useful project definitions
set(MY_SOURCES    "list your sources here")
set(MY_EXECUTABLE super_ar_program)

# create the executable's cmake target
add_executable(${MY_EXECUTABLE} "${MY_SOURCES}")

# the executable against aruco
include_directories(SYSTEM "${ARUCO_INCLUDE}" "${OpenCV_INCLUDE_DIRS}")
target_link_libraries(${MY_EXECUTABLE} ${ARUCO_LIB} ${OpenCV_LIBS})

编辑:我已将脚本更改为使用include_directories() 而不是target_include_directories()

【讨论】:

  • 我应该怎么做,我的意思是..我必须在我的 CMAKE 中用这条线替换 find aruco 行?
  • 我用你的代码更改了 find_package(aruco REQUIRED) 行,我在行末有一个问题:target_include_directories 错误是这样的:未知的 CMake 命令“target_include_directories”。 -- 配置不完整,出现错误!
  • @MarcelloChiurazzi:在您使用的 2.8.3 版本之后,CMake 命令“target_include_directories”已包含在 CMake 中。替代方法是 include_directories(${OpenCV_LIBS}) 之前 add_library() 调用。
  • @MarcelloChiurazzi 查看编辑后的版本。如您所说,只需将find_package(aruco REQUIRED) 替换为提供的命令即可。 (当然,您必须调整路径/名称以适应您的配置/需求)
  • 伙计们的其他错误:(这是行:#创建可执行文件的cmake目标 add_executable(${MY_EXECUTABLE} "${MY_SOURCES}") ERROR:aruco_marker_detector_2/CMakeLists.txt:60 (add_executable):找不到源文件:在此处列出您的源 尝试过的扩展名 .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp .hxx .in .txx 我重新编辑了问题
【解决方案2】:

这是我用 aruco 3.09 简化的 cmake 文件。也应该适用于 3.0+ 的其他版本,只需更改目录名称即可。

cmake_minimum_required( VERSION 2.8 )

## Required software
#find_package( <<<name>>> REQUIRED )

## Sources and headers
include_directories( ${CMAKE_CURRENT_SOURCE_DIR} )
include_directories("/home/corvus/opencv/include/opencv2/")
include_directories("/home/corvus/aruco-3.0.9/aruco-3.0.9/aruco_src/include/")
link_directories( /home/corvus/aruco-3.0.9/aruco-3.0.9/aruco_src/lib/ )

## Find all source and header files to be compiled into object files
file( GLOB SOURCES *.cc *.cpp *.hpp *.hh )

## Find all aruco source and header files to be compiled into object files
## file(GLOB ARUCO_HEADERS "${ARUCO_INCLUDE}/aruco/*.h*")
## file(GLOB ARUCO_SOURCES "${ARUCO_SRC}/*.c*")

## Add OpenCV Library
add_library(OpenCV SHARED IMPORTED)
set_property(TARGET OpenCV PROPERTY IMPORTED_LOCATION "/usr/local/lib")
find_package( OpenCV REQUIRED )

## Add Eigen3
find_package(Eigen3 REQUIRED)

## C++ compiler options
set( CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++11 -pthread -I/usr/include/eigen3/ -L/usr/local/libs \ -lopencv_objdetect \ " )
    ## to disable all warnings 
    ## set( CMAKE_CXX_FLAGS "" ) 
set( CMAKE_CXX_FLAGS_DEBUG "-g -O0" )
set( CMAKE_CXX_FLAGS_RELEASE "-O3" )
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS ON) #...with compiler extensions like gnu++11

## Source file containing the "main" function
set( MAIN_SOURCES main.cpp )
## Specify a name for the generated executable file
set( MAIN_EXE_NAME MarkerDetection )


## 1. Compile...
add_executable( ${MAIN_EXE_NAME} ${MAIN_SOURCES}
                                 ${SOURCES}
              )


## 2. Link...
target_link_libraries( ${MAIN_EXE_NAME} )
target_link_libraries(${MAIN_EXE_NAME} ${OpenCV_LIBS})
target_link_libraries(${MAIN_EXE_NAME} aruco)


## 3. Install...
install( TARGETS ${MAIN_EXE_NAME}
         RUNTIME DESTINATION bin )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-21
    • 2012-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    相关资源
    最近更新 更多