mardi 25 mai 2021

CLion Undefined symbols for architecture arm64 using opencv

I just installed opencv on my MacBook Air (M1) and imported "opencv.h" to my code using CLion, but an error occurred while I run the code:

/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/zdw/CLionProjects/testCLion/cmake-build-debug --target testCLion -- -j 6
Scanning dependencies of target testCLion
[ 33%] Building CXX object CMakeFiles/testCLion.dir/main.cpp.o
[ 66%] Linking CXX executable testCLion
Undefined symbols for architecture arm64:
  "cv::Mat::~Mat()", referenced from:
      _main in main.cpp.o
  "cv::imread(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int)", referenced from:
      _main in main.cpp.o
  "cv::imshow(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cv::_InputArray const&)", referenced from:
      _main in main.cpp.o
  "cv::waitKey(int)", referenced from:
      _main in main.cpp.o
  "cv::Mat::empty() const", referenced from:
      _main in main.cpp.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[3]: *** [testCLion] Error 1
make[2]: *** [CMakeFiles/testCLion.dir/all] Error 2
make[1]: *** [CMakeFiles/testCLion.dir/rule] Error 2
make: *** [testCLion] Error 2

Here is my code:

// main.cpp
#include <iostream>
#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main() {
    Mat img = imread("img/IMG_5910.jpeg");
    if (img.empty()) {
        cout << "error" << endl;
        return -1;
    }

    imshow("myTest1", img);
    waitKey();

    return 0;
}

CMakeList.txt:

cmake_minimum_required(VERSION 3.19)
project(testCLion)

set(CMAKE_CXX_STANDARD 11)

add_executable(testCLion main.cpp support.cpp)

include_directories(/opt/homebrew/Cellar/opencv/4.5.2_4/include/opencv4)

When I tested in terminal and entered pkg-config --libs opencv it shows:

-L/opt/homebrew/Cellar/opencv/4.5.2_4/lib -lopencv_gapi -lopencv_stitching -lopencv_alphamat -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dnn_superres -lopencv_dpm -lopencv_face -lopencv_freetype -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_intensity_transform -lopencv_line_descriptor -lopencv_mcc -lopencv_quality -lopencv_rapid -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_sfm -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_superres -lopencv_optflow -lopencv_surface_matching -lopencv_tracking -lopencv_highgui -lopencv_datasets -lopencv_text -lopencv_plot -lopencv_videostab -lopencv_videoio -lopencv_viz -lopencv_wechat_qrcode -lopencv_xfeatures2d -lopencv_shape -lopencv_ml -lopencv_ximgproc -lopencv_video -lopencv_dnn -lopencv_xobjdetect -lopencv_objdetect -lopencv_calib3d -lopencv_imgcodecs -lopencv_features2d -lopencv_flann -lopencv_xphoto -lopencv_photo -lopencv_imgproc -lopencv_core

Aucun commentaire:

Enregistrer un commentaire