对于一个学校项目,我想在CLion上安装OpenCV。
我下载了适用于windows的OpenCV安装程序,并在C:disk上提取了OpenCV。我在系统环境变量中添加了OpenCV lib和bin文件夹的路径。
这是我的CMakeList.txt文件:
cmake_minimum_required(VERSION 3.23)
project(poumons VERSION 0.1.0)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable(poumons main.cpp)
target_link_libraries( poumons ${OpenCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
以下是CMake构建的输出:
"C:Program FilesJetBrainsCLion 2022.2.4bincmakewinbincmake.exe" -DCMAKE_BUILD_TYPE=Debug "-DCMAKE_MAKE_PROGRAM=C:/Program Files/JetBrains/CLion 2022.2.4/bin/ninja/win/ninja.exe" -G Ninja -S C:UsersaxellCLionProjectspoumons -B C:UsersaxellCLionProjectspoumonscmake-build-debug
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/axell/CLionProjects/poumons/cmake-build-debug
[Finished]
这是源文件:
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv;
int main() {
std::cout << "Hello, World!" << std::endl;
/*Mat image;
image = imread("./moi.png");
imshow("fenetre" ,image);
waitKey(0);*/
cv::Mat image2;
return 0;
}
但当我构建项目时,这里是输出:
====================[ Build | all | Debug ]=====================================
"C:Program FilesJetBrainsCLion 2022.2.4bincmakewinbincmake.exe" --build C:UsersaxellCLionProjectspoumonscmake-build-debug --target all -j 6
[1/1] Linking CXX executable poumons.exe
FAILED: poumons.exe
cmd.exe /C "cd . && C:PROGRA~1JETBRA~1CLION2~1.4binmingwbinG__~1.EXE -g CMakeFiles/poumons.dir/main.cpp.obj -o poumons.exe -Wl,--out-implib,libpoumons.dll.a -Wl,--major-image-version,0,--minor-image-version,0 C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib C:/opencv/build/x64/vc15/lib/opencv_world460d.lib -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:Program FilesJetBrainsCLion 2022.2.4binmingwbin/ld.exe: CMakeFiles/poumons.dir/main.cpp.obj:C:/Users/axell/CLionProjects/poumons/main.cpp:12: undefined reference to `cv::Mat::Mat()'
C:Program FilesJetBrainsCLion 2022.2.4binmingwbin/ld.exe: CMakeFiles/poumons.dir/main.cpp.obj: in function `main':
C:/Users/axell/CLionProjects/poumons/main.cpp:14: undefined reference to `cv::Mat::~Mat()'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
我试着使用Visual Studio代码来查看我的OpenCV是否安装正确,它运行得很好,但在CLion上没有。
我不知道我错过了什么或做错了什么。
谢谢。
我也面临同样的问题。对于解决方案,我只需编辑clion构建设置就足够了。你在visual studio代码中使用的是哪个构建,你应该像这样编辑你的clion设置。在这里输入图像描述