Mac M1下Clion编译错误:Undefined symbols for architecture x86_64和ld: symbol(s) not found for architecture

问题:

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

Mac M1下Clion编译错误:Undefined symbols for architecture x86_64和ld: symbol(s) not found for architecture_第1张图片
main.cp如下:

#include 
#include 
#include 
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})

你可能感兴趣的:(问题,c++,macos)