Программы на C++. Форум разработчиков
Гость
OpenCV неправильно связывается с CMake [дубликат]
Сообщение
Гость » 12 мар 2024, 11:10
Код: Выделить всё
PS C:\Users\home\OneDrive\Documents\CODE STUFF\C++\ComputerVision\build> ninja
[2/2] Linking CXX executable ComputerVision.exe
FAILED: ComputerVision.exe
C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe -g CMakeFiles/ComputerVision.dir/main.cpp.obj -o ComputerVision.exe -Wl,--out-implib,libComputerVision.dll.a -Wl,--major-image-version,0,--minor-image-version,0 "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/ComputerVision.dir/main.cpp.obj: in function `main':
C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:9:(.text+0x4d): undefined reference to `cv::imread(std::__cxx11::basic_string const&, int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:12:(.text+0x71): undefined reference to `cv::Mat::empty() const'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:18:(.text+0xf1): undefined reference to `cv::imshow(std::__cxx11::basic_string const&, cv::_InputArray const&)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:21:(.text+0x120): undefined reference to `cv::waitKey(int)'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:24:(.text+0x125): undefined reference to `cv::destroyAllWindows()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:27:(.text+0x136): undefined reference to `cv::Mat::~Mat()'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:27:(.text+0x1a3): undefined reference to `cv::Mat::~Mat()'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
Эту ошибку я получаю, когда пытаюсь связать библиотеки из OpenCV с моим файлом main.cpp. Я не уверен, как я могу это исправить. Согласно файлу CMakeList.txt пути должны быть правильными. Я даже включил их в переменные среды.
Вот мой файл CMakeLists.txt:
Код: Выделить всё
cmake_minimum_required(VERSION 3.28.3)
project(ComputerVision VERSION 0.1.0 LANGUAGES C CXX)
include(CTest)
enable_testing()
find_package(OpenCV REQUIRED)
# Set the directory where OpenCV is installed
set(OpenCV_DIR "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build")
# Print the value of OpenCV_INCLUDE_DIRS
message(STATUS "OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}")
add_executable(ComputerVision main.cpp)
# Link against OpenCV libraries
target_link_libraries(ComputerVision PRIVATE ${OpenCV_LIBS})
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
and my main.cpp file:
Код: Выделить всё
#include
#include
using namespace cv;
using namespace std;
int main() {
// Read an image file
Mat image = imread("image.jpg");
// Check if the image was loaded successfully
if (image.empty()) {
cout
Источник: [url]https://stackoverflow.com/questions/78145497/opencv-isnt-linking-properly-with-cmake[/url]
1710231018
Гость
[code]PS C:\Users\home\OneDrive\Documents\CODE STUFF\C++\ComputerVision\build> ninja [2/2] Linking CXX executable ComputerVision.exe FAILED: ComputerVision.exe C:\WINDOWS\system32\cmd.exe /C "cd . && C:\msys64\mingw64\bin\g++.exe -g CMakeFiles/ComputerVision.dir/main.cpp.obj -o ComputerVision.exe -Wl,--out-implib,libComputerVision.dll.a -Wl,--major-image-version,0,--minor-image-version,0 "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build/x64/vc16/lib/opencv_world490d.lib" -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ." C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: CMakeFiles/ComputerVision.dir/main.cpp.obj: in function `main': C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:9:(.text+0x4d): undefined reference to `cv::imread(std::__cxx11::basic_string const&, int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:12:(.text+0x71): undefined reference to `cv::Mat::empty() const' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:18:(.text+0xf1): undefined reference to `cv::imshow(std::__cxx11::basic_string const&, cv::_InputArray const&)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:21:(.text+0x120): undefined reference to `cv::waitKey(int)' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:24:(.text+0x125): undefined reference to `cv::destroyAllWindows()' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:27:(.text+0x136): undefined reference to `cv::Mat::~Mat()' C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:/Users/home/OneDrive/Documents/CODE STUFF/C++/ComputerVision/main.cpp:27:(.text+0x1a3): undefined reference to `cv::Mat::~Mat()' collect2.exe: error: ld returned 1 exit status ninja: build stopped: subcommand failed. [/code] Эту ошибку я получаю, когда пытаюсь связать библиотеки из OpenCV с моим файлом main.cpp. Я не уверен, как я могу это исправить. Согласно файлу CMakeList.txt пути должны быть правильными. Я даже включил их в переменные среды. Вот мой файл CMakeLists.txt: [code]cmake_minimum_required(VERSION 3.28.3) project(ComputerVision VERSION 0.1.0 LANGUAGES C CXX) include(CTest) enable_testing() find_package(OpenCV REQUIRED) # Set the directory where OpenCV is installed set(OpenCV_DIR "C:/Users/home/OneDrive/Documents/CODE STUFF/opencv/build") # Print the value of OpenCV_INCLUDE_DIRS message(STATUS "OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}") add_executable(ComputerVision main.cpp) # Link against OpenCV libraries target_link_libraries(ComputerVision PRIVATE ${OpenCV_LIBS}) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack) [/code] and my main.cpp file: [code]#include #include using namespace cv; using namespace std; int main() { // Read an image file Mat image = imread("image.jpg"); // Check if the image was loaded successfully if (image.empty()) { cout Источник: [url]https://stackoverflow.com/questions/78145497/opencv-isnt-linking-properly-with-cmake[/url]