How can I build project, dependent on opencv 3.4.0 in RelWithDebInfo mode
Asked Answered
C

2

6

Here is my main cmake file:

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)

and my subproject file:

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

But I can't build in RelWithDebInfo mode, in this case MSVC gives me these link errors:

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)

(Debug/Release builds ok) How can I fix this?

Callisthenics answered 24/3, 2018 at 6:46 Comment(4)
See these related links: 10105, 9656. Either update to the latest OpenCV version or update your OpenCV version with the corresponding fixes.Titular
Maybe your OpenCV version is not for your project, or you have wrote the wrong code. In OpenCV 3.4, I can't find the functions type either.Nonchalance
@Silencer It's still in masterReflexive
Tried to replace 3.4.1 with master branch, but I still get link error in RelWithDebInfo mode.Callisthenics
C
3

Even though I was unable to build in RelWithDebInfo mode, I've found a workaround. Enable debug info in your MSVC project and it will allow you to trace crash stack position:

enter image description here

enter image description here

enter image description here

Callisthenics answered 13/4, 2018 at 13:38 Comment(0)
B
0

I also had very often trouble using libraries with different build configurations. My solution is building every dependency with the same compiler flags as im building the project. Therefore I either add the project in cmake using the ExternalProject package or build the library multiple times with different configurations. With the second solution you will have to adjust your OpenCV_Dir respectively. However sometimes you just have to try to link the release/debug version when build in RelWithDebInfo mode and one will work.

Bloomers answered 8/4, 2018 at 21:6 Comment(1)
plz provide some clear instructions, unfortunately I don't understand what to do.Callisthenics

© 2022 - 2024 — McMap. All rights reserved.