Ask Your Question

Revision history [back]

ld: symbol(s) not found for architecture x86_64

Hello everyone! I cannot build the following cpp-file with g++ on macOS Mojave (Version 10.14.5):

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

using namespace std;
using namespace cv;
int main(int, char *argv[]){
    Mat in_image, out_image;
    in_image = imread(argv[1], IMREAD_UNCHANGED);
    return 0;
}

I build the file with:

$ g++ `pkg-config --cflags --libs opencv4` -std=c++17  demo.cpp

But I got this error message:

Undefined symbols for architecture x86_64:
  "cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)", referenced from:
      _main in cczhuuKm.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

The g++, pkg-config, opencv were all installed via HomeBrew. The versions are:

$ g++ --version
g++ (Homebrew GCC 9.1.0) 9.1.0

$ pkg-config --version
0.29.2

$ opencv_version
4.1.0

How can I solve this error? Pls help 🙏🏽 !