问题:
Undefined symbols for architecture arm64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
解决:
去掉了C编译环境和C++编译环境
/opt/homebrew/Cellar/gcc/13.1.0/bin/g++-13
/opt/homebrew/Cellar/gcc/13.1.0/bin/gcc-13
main.cp如下:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main() {
cv::Mat image = cv::imread("/Users/xinwu/Desktop/opencv_demo/00.jpg");
cout<<image.size<<endl;
imshow("tuxiang",image);
cv::waitKey(0);
std::cout << "Hello, World!" << std::endl;
return 0;
}
CMakeLists.txt,注意cmake版本与你安装的一致
add_executable()
和target_linnk_libraries()
顺序不能写,如下:
cmake_minimum_required(VERSION 3.26)
project(opencv_demo)
set(CMAKE_CXX_STANDARD 11)
find_package(OpenCV)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(opencv_demo main.cpp)
target_link_libraries(opencv_demo ${OpenCV_LIBS})