【问题标题】:How can I build project, dependent on opencv 3.4.0 in RelWithDebInfo mode如何在 RelWithDebInfo 模式下构建项目,依赖于 opencv 3.4.0
【发布时间】:2018-03-24 06:46:35
【问题描述】:

这是我的主要 cmake 文件:

project( reconstructor )                                    
cmake_minimum_required(VERSION 3.1)
set(CMAKE_SUPPRESS_REGENERATION true)
include(ExternalProject)
set(Boost_INCLUDE_DIR c:/boost_1_66_0)
set(Boost_LIBRARY_DIR C:/boost_1_66_0/lib64-msvc-14.0 )
SET("OpenCV_DIR" "C:/opencv-3.4.0/build")
find_package( OpenCV COMPONENTS core imgproc highgui aruco optflow REQUIRED )
add_subdirectory(prepare_folder)
add_subdirectory(draw_signal)
add_subdirectory(epipolar_reconstructor)
add_subdirectory(test_detection)
add_subdirectory(homography_matcher)
add_subdirectory(multiview)
add_subdirectory(filter_clouds)
add_subdirectory(filter_clouds_solid)
add_subdirectory(optical_flow)
add_subdirectory(prepare_splices)
add_subdirectory(skew_matcher)
add_subdirectory(triangle_matcher)

和我的子项目文件:

cmake_minimum_required(VERSION 3.1)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
get_filename_component(CUR_PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
find_package(Boost COMPONENTS system filesystem REQUIRED)
link_directories(${Boost_LIBRARY_DIR})            
FILE(GLOB cpps *.cpp)
FILE(GLOB commons ../common/*.c*)
add_executable( ${CUR_PROJECT_NAME}  ${cpps} ${commons})
set_target_properties(${CUR_PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
include_directories(${Boost_INCLUDE_DIR})
target_link_libraries( ${CUR_PROJECT_NAME} ${OpenCV_LIBS} ${Boost_LIBRARIES})

但我无法在 RelWithDebInfo 模式下构建,在这种情况下 MSVC 会给我这些链接错误:

1>epipolar_reconstructor.obj : error LNK2019: unresolved external symbol "void __cdecl cv::Rodrigues(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &)" (?Rodrigues@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@1@Z) referenced in function "struct std::pair<class cv::Mat,class cv::Mat> __cdecl calcR(struct View &,struct View &)" (?calcR@@YA?AU?$pair@VMat@cv@@V12@@std@@AEAUView@@0@Z)
1>triangulate.obj : error LNK2001: unresolved external symbol "void __cdecl cv::Rodrigues(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &)" (?Rodrigues@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@1@Z)
1>epipolar_reconstructor.obj : error LNK2019: unresolved external symbol "void __cdecl cv::stereoRectify(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &,class cv::Size_<int>,class cv::_InputArray const &,class cv::_InputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &,class cv::_OutputArray const &,int,double,class cv::Size_<int>,class cv::Rect_<int> *,class cv::Rect_<int> *)" (?stereoRectify@cv@@YAXAEBV_InputArray@1@000V?$Size_@H@1@00AEBV_OutputArray@1@2222HN1PEAV?$Rect_@H@1@3@Z) referenced in function "void __cdecl handlePair(struct View &,struct View &,struct Folder &)" (?handlePair@@YAXAEAUView@@0AEAUFolder@@@Z)

(调试/发布构建正常)我该如何解决这个问题?

【问题讨论】:

  • 查看这些相关链接:101059656。更新到最新的 OpenCV 版本或使用相应的修复更新您的 OpenCV 版本。
  • 可能你的 OpenCV 版本不适合你的项目,或者你写错了代码。在OpenCV 3.4,我也找不到函数类型。
  • @Silencer 这是still in master
  • 尝试用 master 分支替换 3.4.1,但在 RelWithDebInfo 模式下仍然出现链接错误。

标签: c++ opencv cmake debug-symbols


【解决方案1】:

尽管我无法在 RelWithDebInfo 模式下构建,但我找到了一种解决方法。在您的 MSVC 项目中启用调试信息,它将允许您跟踪崩溃堆栈位置:

【讨论】:

    【解决方案2】:

    在使用具有不同构建配置的库时,我也经常遇到麻烦。我的解决方案是使用与构建项目相同的编译器标志来构建每个依赖项。因此,我要么使用 ExternalProject 包在 cmake 中添加项目,要么使用不同的配置多次构建库。使用第二种解决方案,您将不得不分别调整您的 OpenCV_Dir。但是,有时您只需要在以 RelWithDebInfo 模式构建时尝试链接发布/调试版本即可。

    【讨论】:

    • 请提供一些明确的说明,不幸的是我不明白该怎么做。
    猜你喜欢
    • 1970-01-01
    • 2010-11-17
    • 2020-07-24
    • 2014-10-18
    • 1970-01-01
    • 1970-01-01
    • 2013-01-30
    • 2012-08-20
    相关资源
    最近更新 更多