Mac(m1) clion编译opencv报错building for macOS-x86_64 but attempting to link with file built for macOS-ar
Posted 行者如风dev
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Mac(m1) clion编译opencv报错building for macOS-x86_64 but attempting to link with file built for macOS-ar相关的知识,希望对你有一定的参考价值。
代码如下:
具体报错如下:
ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_dnn.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_video.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_datasets.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_videoio.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_objdetect.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_imgcodecs.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_imgproc.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_flann.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_calib3d.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_photo.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64ld: warning: ignoring file /opt/homebrew/opt/opencv@3/lib/libopencv_features2d.3.4.16.dylib, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
解决办法:
在cmake中添加编译选项:
mac10.12.6系统配置clion编写CMakeLists文件运行opencv3
按照mac10.12.6系统使用cmake安装opencv3.3.0+opencv_contrib-3.3.0下载编译安装好了文件以后,装好clion编译器,新建C++可执行工程,编写代码
opecv3代码
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
Mat srcImage = imread("1.png");
if (!srcImage.data) {
std::cout << "Image not loaded";
return -1;
}
imshow("[img]", srcImage);
waitKey(0);
return 0;
}
CMakeLists文件
cmake_minimum_required(VERSION 3.12)
project(OpenCVGrad)
set(CMAKE_CXX_STANDARD 11)
#
FIND_PACKAGE(OpenCV REQUIRED)
#
add_executable(OpenCVGrad main.cpp)
#
target_link_libraries(OpenCVGrad ${OpenCV_LIBS})
#
运行成功
参考感谢
以上是关于Mac(m1) clion编译opencv报错building for macOS-x86_64 but attempting to link with file built for macOS-ar的主要内容,如果未能解决你的问题,请参考以下文章
OpenCV3.3.0 + CLion + CMake 配置(Mac巨细无敌版)
CPP小记:CLion for Mac报错Ignoring CMAKE_OSX_SYSROOT value,XCode not exist