0

I am trying to compile Aruco using their short example. I am using Mac OS X (10.13.2), the compiler is clang (900.0.39.2), opencv (3.4.1_2 installed via brew) and Aruco (3.0.4).

The simple example is:

#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;
  }
}

My CMakeLists.txt is:

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)

And the error I get when running make (after running cmake with no issues) is:

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

I am fairly new to compiling (as maybe obvious!)

kungphil
  • 1,759
  • 2
  • 18
  • 27
  • I guess you'll also need a `find_package(...)` for OpenCV and so on. – Mark Setchell Apr 16 '18 at 12:57
  • Thanks @MarkSetchell, I added `find_package(OpenCV REQUIRED)` to my makefile which when running `cmake` printed `Found OpenCV: /usr/local (found version "3.4.1")`. But I still get the same error when running `make`. – kungphil Apr 16 '18 at 13:09
  • 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) – underscore_d Apr 16 '18 at 13:14

1 Answers1

0

The last line of my makefile need to be

target_link_libraries(aruco_simple  aruco ${OpenCV_LIBS})
kungphil
  • 1,759
  • 2
  • 18
  • 27
  • Thank you for sharing your findings back with the community. Consider clicking `edit` under your answer and adding a **complete** `CMakeLists.txt` that works for this software combination and then accepting your own answer :-) – Mark Setchell Apr 16 '18 at 17:46