在Windows10 VS Code上使用CMake读取的opencv未定义引用

时间:2018-09-11 18:11:57

标签: c++ windows opencv cmake visual-studio-code

我想在带有CMake的VS Code IDE上运行OpenCV,但它显示for。我已经尝试了几种方法(例如,编辑PATH变量...)来解决该问题,但是它仍然可以链接到opencv库。

  • 这是我的undefined reference to cv::imread()

    CMakelists.txt
  • 完成CMake设置后,我运行# cmake needs this line cmake_minimum_required(VERSION 2.8) # Enable C++11 set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED TRUE) # Define project name project(cvtest) # Find OpenCV, you may need to set OpenCV_DIR variable # to the absolute path to the directory containing OpenCVConfig.cmake file # via the command line or GUI find_package(OpenCV REQUIRED) set(OpenCV_INCLUDE_DIRS "C:/opencv/build/include") include_directories(${OpenCV_INCLUDE_DIRS}) # If the package has been found, several variables will # be set, you can find the full list with descriptions # in the OpenCVConfig.cmake file. # Print some message showing some of them message(STATUS "OpenCV library status:") message(STATUS " version: ${OpenCV_VERSION}") message(STATUS " libraries: ${OpenCV_LIBS}") message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}") # Declare the executable target built from your sources add_executable(cvtest cvtest.cpp) # Link your application with OpenCV libraries target_link_libraries(cvtest ${OpenCV_LIBS})

    $ cmake -G "MinGW Makefiles"
  • 最后,我运行 -- OpenCV library status: -- version: 2.4.13.6 -- libraries: opencv_videostab;opencv_video;opencv_ts;opencv_superres;opencv_stitching;opencv_photo;opencv_ocl;opencv_objdetect;opencv_nonfree;opencv_ml;opencv_legacy;opencv_imgproc;opencv_highgui;opencv_gpu;opencv_flann;opencv_features2d;opencv_core;opencv_contrib;opencv_calib3d -- include path: C:/opencv/build/include ,但是它出了一些错误

    $ mingw32-make
  • 这里是Scanning dependencies of target cvtest [ 50%] Building CXX object CMakeFiles/cvtest.dir/cvtest.cpp.obj [100%] Linking CXX executable cvtest.exe CMakeFiles\cvtest.dir/objects.a(cvtest.cpp.obj):cvtest.cpp:(.text+0x63): undefined reference to cv::imread(std::string const&, int)' CMakeFiles\cvtest.dir/objects.a(cvtest.cpp.obj):cvtest.cpp:(.text+0x87): undefined reference to cv::_InputArray::_InputArray(cv::Mat const&)' CMakeFiles\cvtest.dir/objects.a(cvtest.cpp.obj):cvtest.cpp:(.text+0xc1): undefined reference to cv::imshow(std::string const&, cv::_InputArray const&)' c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: CMakeFiles\cvtest.dir/objects.a(cvtest.cpp.obj): bad reloc address 0xf in section `.text$_ZN2cv3MatD1Ev[__ZN2cv3MatD1Ev]' c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation collect2.exe: error: ld returned 1 exit status CMakeFiles\cvtest.dir\build.make:104: recipe for target 'cvtest.exe' failed mingw32-make[2]: *** [cvtest.exe] Error 1 CMakeFiles\Makefile2:71: recipe for target 'CMakeFiles/cvtest.dir/all' failed mingw32-make[1]: *** [CMakeFiles/cvtest.dir/all] Error 2 Makefile:82: recipe for target 'all' failed mingw32-make: *** [all] Error 2

    cvtest.cpp

我是否误解了一些我应该知道的东西,我该如何纠正?谢谢!

0 个答案:

没有答案