I am trying to use sfm module for opencv. The problem is linking that. So, let's see the code.
main.cpp:
...
cv::sfm::reconstruct(images_paths, Rs_est, ts_est, K2, points3d_estimated, true)
...
I compiled this code to main.o. And now, I would like to link it with libopencv_core.so and libopencv_sfm.so . The second one file contains a definition of function 'reconstruct'. Why am I sure? When I type:
nm -D libopencv_sfm.so | grep reconstruct
I got:
00000000000b4ca0 T _ZN2cv3sfm11reconstructERKNS_11_InputArrayERKNS_12_OutputArrayES6_RKNS_17_InputOutputArrayEb
00000000000b4ba0 T _ZN2cv3sfm11reconstructERKNS_11_InputArrayERKNS_12_OutputArrayES6_RKNS_17_InputOutputArrayES6_b
00000000000b2650 T _ZN2cv3sfm11reconstructESt6vectorISsSaISsEERKNS_12_OutputArrayES6_RKNS_17_InputOutputArrayEb
00000000000b2550 T _ZN2cv3sfm11reconstructESt6vectorISsSaISsEERKNS_12_OutputArrayES6_RKNS_17_InputOutputArrayES6_b
I checked signature of reconstruct function in main.o file. And it match to:
_ZN2cv3sfm11reconstructESt6vectorISsSaISsEERKNS_12_OutputArrayES6_RKNS_17_InputOutputArrayES6_b
So the shared library contains definition of reconstruct.
So now, I link:
g++ libopencv_core.so libopencv_sfm.so main.o -o main
and it gives me error:
undefined reference to `cv::sfm::reconstruct(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, cv::_OutputArray const&, cv::_OutputArray const&, cv::_InputOutputArray const&, cv::_OutputArray const&, bool)'
And I don't understand. After all libopencv_sfm.so contains definition of that function!
And please: don't tell me: use cmake. I tried use cmake and the problem is the same. So I try to understand it on low level.
Thanks in advance.
(gcc version: 5.1.1)