在Mac OS X上编译Aruco时出错:架构x86_64的未定义符号:

时间:2018-04-16 12:48:43

标签: c++ macos opencv3.0 aruco

我正在尝试使用他们的短example来编译Aruco。我使用的是Mac OS X(10.13.2),编译器是clang(900.0.39.2),opencv(通过brew安装的是3.4.1_2)和Aruco(3.0.4)。

简单的例子是:

#include <iostream>
#include <aruco/aruco.h>
#include <opencv2/highgui.hpp>
int main(int argc,char **argv)
{
  try
  {
      if (argc!=2) throw std::runtime_error("Usage: inimage");
      aruco::MarkerDetector MDetector;
      //read the input image
      cv::Mat InImage=cv::imread(argv[1]);
    //Ok, let's detect
      MDetector.setDictionary("ARUCO_MIP_36h12");
      //detect markers and for each one, draw info and its boundaries in the image
      for(auto m:MDetector.detect(InImage)){
          std::cout<<m<<std::endl;
          m.draw(InImage);
      }
      cv::imshow("in",InImage);
      cv::waitKey(0);//wait for key to be pressed
  } catch (std::exception &ex)
  {
      std::cout<<"Exception :"<<ex.what()<<std::endl;
  }
}

我的CMakeLists.txt是:

cmake_minimum_required(VERSION 2.8)
project(aruco_testproject)
SET(CMAKE_CXX_FLAGS "-std=c++11")
find_package(aruco REQUIRED )
add_executable(aruco_simple aruco_simple.cpp)
target_link_libraries(aruco_simple  aruco)

运行make时(运行cmake后没有问题)我得到的错误是:

Scanning dependencies of target aruco_simple
[ 50%] Building CXX object CMakeFiles/aruco_simple.dir/aruco_simple.cpp.o
[100%] Linking CXX executable aruco_simple
Undefined symbols for architecture x86_64:
  "cv::imread(cv::String const&, int)", referenced from:
      _main in aruco_simple.cpp.o
  "cv::imshow(cv::String const&, cv::_InputArray const&)", referenced from:
      _main in aruco_simple.cpp.o
  "cv::waitKey(int)", referenced from:
      _main in aruco_simple.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [aruco_simple] Error 1
make[1]: *** [CMakeFiles/aruco_simple.dir/all] Error 2
make: *** [all] Error 2

我对编译很新(可能很明显!)

1 个答案:

答案 0 :(得分:0)

我的makefile的最后一行需要

target_link_libraries(aruco_simple  aruco ${OpenCV_LIBS})