Ceres c++ error when used in voxl2 project
-
Hi there
I am running a structure from motion pipeline on voxl2 and this pipeline needs in a prior step the bundle adjustment solver Ceres. I know that on voxl this pipeline worked but now for some reason on voxl2 I can build Ceres but when building the project that depends on Ceres I get an error saying that the std::vector = operator is an undefined reference. (see attached image)
Any ideas how to resolve this? I tried moving from c++ 11 in the cmake to c++14 but I think that's a bad approach as the assignment operator for std::vectors was introduced in c++ 98. I also tried using a specific voxl Ceres that I built using voxl docker but that yielded many other errors indicating a doubtful implementation.
Any ideas how to resolve this? Thanks in advance.
-
@lfierz , this could happen if you built Ceres using a different build environment (different version of gcc / libstdc++). Are you building Ceres and your project natively on VOXL2 with the same C++ dialect?
Alex
-
@Alex-Kushleyev I'm not exactly sure what to look for when looking for the c++ dialect used. There are no CXX_STANDARD statements in either CMakeLists.txt file. So I suppose they are both using the default (don't know what that is).
My project does use C++14 while Ceres 1.14 which I try to include uses c++11 but I tried with c++14 there as well as mentioned previously yielding the same error.
-
@lfierz also please double check that you are linking against libstdc++ ..
Additionally, since it seems you are using a static library libceres.a , with static libraries, the link order matters, so make sure that -lstdc++ is after -lceres in your link command.
-
@Alex-Kushleyev Thanks for the hint. I now added the stdc++ to the linked libs like so:
target_link_libraries(${PROJECT_NAME}_tracker_node stdc++ ${CERES_LIBRARIES})
It still yields the same error sadly. I also tried linking stdc++ in a separate target_link_libraries statement which also yielded the same error. -
@Alex-Kushleyev I'm quite sure that I use the g++ compiler for both builds. neither clang nor msvc are installed.
-
@lfierz said in Ceres c++ error when used in voxl2 project:
target_link_libraries(${PROJECT_NAME}_tracker_node stdc++ ${CERES_LIBRARIES})
please try to switch link order of the libraries, specifically:
target_link_libraries(${PROJECT_NAME}_tracker_node ${CERES_LIBRARIES} stdc++)
The static libraries should come first. see https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc
also, if you enable verbose cmake, you can actually see the linker command and make sure it has
-lceres -lstdc++
in that orderAlternatively.. if you build Ceres as dynamic library, it should figure out the dependencies at run time..
-
@Alex-Kushleyev building Ceres as a dynamically linked library solved it. You are hero material thank you!
-
@lfierz , excellent! I am glad that it worked