我用c++和OpenCV写了一段代码:
#include <iostream>
#include <time.h>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
int main()
{
...
return 0;
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试在终端上运行我的代码并使用 g++ 进行构建:
g++ $(pkg-config --cflags --libs opencv) -std=c++11 yourFile.cpp -o yourFileProgram
Run Code Online (Sandbox Code Playgroud)
但我收到此错误:
...
ld: warning: ignoring file /opt/homebrew/Cellar/opencv/4.5.1_2/lib/libopencv_core.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/Cellar/opencv/4.5.1_2/lib/libopencv_photo.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:
"cv::Mat::Mat()", referenced from:
_main in cv_test-ff1014.o
"cv::Mat::~Mat()", referenced …Run Code Online (Sandbox Code Playgroud) 我OpenCV2在XCode中设置但不幸的imshow是不起作用:
Undefined symbols for architecture x86_64:
"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.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我正在使用最新的XCode运行OS X 10.8.4.
我在下面附上了一些图像,以显示XCode和库中的设置.到目前为止,似乎其他功能与OpenCV一起工作正常,除此之外.

