OS X 上的 libg2o 链接器错误



我收到以下链接器错误:

cd /Users/mhoggan/Development/bluenote/image_pose_adjustment/image_pose_adjustment/native/graph/cmake-build-debug/src && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/graph_optimization.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++    -std=c++11 -Wall -Werror -O3 -DNDEBUG -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/graph_optimization.dir/main.cpp.o CMakeFiles/graph_optimization.dir/BundleRigidGraphOptimizer.cpp.o CMakeFiles/graph_optimization.dir/FlexibleGraphOptimizer.cpp.o CMakeFiles/graph_optimization.dir/LoopClosure.cpp.o CMakeFiles/graph_optimization.dir/PoseJsonReader.cpp.o  -o graph_optimization  -L/Users/mhoggan/Development/bluenote/image_pose_adjustment/image_pose_adjustment/native/graph/cmake-build-debug/g2o-src/lib  /usr/local/lib/libboost_filesystem-mt.a /usr/local/lib/libboost_system-mt.a -lg2o_cli -lg2o_core -lg2o_interface -lg2o_parser -lg2o_solver_csparse -lg2o_solver_dense -lg2o_solver_pcg -lg2o_stuff -lg2o_types_icp -lg2o_types_sba -lg2o_types_sim3 -lg2o_types_slam2d -lg2o_types_slam3d -lg2o_csparse_extension -lcsparse -ljsoncpp -Wl,-rpath,/Users/mhoggan/Development/bluenote/image_pose_adjustment/image_pose_adjustment/native/graph/cmake-build-debug/g2o-src/lib 
Undefined symbols for architecture x86_64:
"g2o::csparse_extension::cs_cholsolsymb(cs_sparse const*, double*, cs_symbolic const*, double*, int*)", referenced from:
g2o::LinearSolverCSparse<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::solve(g2o::SparseBlockMatrix<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, double*, double*) in LoopClosure.cpp.o
"g2o::csparse_extension::writeCs2Octave(char const*, cs_sparse const*, bool)", referenced from:
g2o::LinearSolverCSparse<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::solve(g2o::SparseBlockMatrix<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, double*, double*) in LoopClosure.cpp.o
"g2o::csparse_extension::cs_chol_workspace(cs_sparse const*, cs_symbolic const*, int*, double*)", referenced from:
g2o::LinearSolverCSparse<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::solveBlocks(double**&, g2o::SparseBlockMatrix<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&) in LoopClosure.cpp.o
g2o::LinearSolverCSparse<Eigen::Matrix<double, -1, -1, 0, -1, -1> >::solvePattern(g2o::SparseBlockMatrix<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, std::__1::vector<std::__1::pair<int, int>, std::__1::allocator<std::__1::pair<int, int> > > const&, g2o::SparseBlockMatrix<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&) in LoopClosure.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

当链接到 G2O 时。

该库列在它所链接的那些中,nm 显示符号在那里。

mhoggan-C02S81PRG8WM:graph mhoggan$ nm /Users/mhoggan/Development/bluenote/image_pose_adjustment/image_pose_adjustment/native/graph/cmake-build-debug/g2o-src/lib/libg2o_csparse_extension.dylib | grep cs_cholsolsymb
0000000000002120 T __ZN3g2o17csparse_extension14cs_cholsolsymbEPK12cs_di_sparsePdPK14cs_di_symbolicS4_Pi
mhoggan-C02S81PRG8WM:graph mhoggan$ nm /Users/mhoggan/Development/bluenote/image_pose_adjustment/image_pose_adjustment/native/graph/cmake-build-debug/g2o-src/lib/libg2o_csparse_extension.dylib | grep writeCs2Octave
00000000000027d0 T __ZN3g2o17csparse_extension14writeCs2OctaveEPKcPK12cs_di_sparseb
mhoggan-C02S81PRG8WM:graph mhoggan$ nm /Users/mhoggan/Development/bluenote/image_pose_adjustment/image_pose_adjustment/native/graph/cmake-build-debug/g2o-src/lib/libg2o_csparse_extension.dylib | grep cs_chol_workspace
0000000000002210 T __ZN3g2o17csparse_extension17cs_chol_workspaceEPK12cs_di_sparsePK14cs_di_symbolicPiPd

要重现此问题,请按照下列步骤操作:

brew update
// basic dependencies
brew install pkg-config cmake git
// g2o dependencies
brew install suite-sparse
// OpenCV dependencies and OpenCV
brew install eigen
brew install ffmpeg
brew install opencv
// other dependencies
brew install yaml-cpp glog gflags
// Node.js
brew install node

现在,要获取链接器错误,请执行以下操作:

cd /path/to/working/dir
git clone https://github.com/RainerKuemmerle/g2o.git
cd g2o
git checkout 9b41a4ea5ade8e1250b9c1b279f3a9c098811b5a
mkdir build && cd build
cmake 
-DCMAKE_BUILD_TYPE=Release 
-DCMAKE_INSTALL_PREFIX=/usr/local 
-DCMAKE_CXX_FLAGS=-std=c++11 
-DBUILD_SHARED_LIBS=ON 
-DBUILD_UNITTESTS=OFF 
-DG2O_USE_CHOLMOD=OFF 
-DG2O_USE_CSPARSE=ON 
-DG2O_USE_OPENGL=OFF 
-DG2O_USE_OPENMP=ON 
..
make -j4
make install

这应该会产生上面记录的链接器错误。

从原始报告中突出的一件事是,缺少的符号是:

g2o::csparse_extension::cs_cholsolsymb(cs_sparse const*, double*, cs_symbolic const*, double*, int*)
g2o::csparse_extension::writeCs2Octave(char const*, cs_sparse const*, bool)
g2o::csparse_extension::cs_chol_workspace(cs_sparse const*, cs_symbolic const*, int*, double*)

而最初的记者认为,这些符号是在其构建输出libg2o_csparse_extension.dylib中定义的:

__ZN3g2o17csparse_extension14cs_cholsolsymbEPK12cs_di_sparsePdPK14cs_di_symbolicS4_Pi
__ZN3g2o17csparse_extension14writeCs2OctaveEPKcPK12cs_di_sparseb
__ZN3g2o17csparse_extension17cs_chol_workspaceEPK12cs_di_sparsePK14cs_di_symbolicPiPd

但是,如果您对这些符号进行解散(例如使用c++filt),您可以看到这些符号实际上是:

g2o::csparse_extension::cs_cholsolsymb(cs_di_sparse const*, double*, cs_di_symbolic const*, double*, int*)
g2o::csparse_extension::writeCs2Octave(char const*, cs_di_sparse const*, bool)
g2o::csparse_extension::cs_chol_workspace(cs_di_sparse const*, cs_di_symbolic const*, int*, double*)

区别在于使用cs_sparsecs_symboliccs_di_sparsecs_di_symbolic

现在,在我的 Mac 上,运行您提供的命令工作正常(与关于<omp.h>和 GCC 的 @alex-reinking 具有相同的警告),但构建的库包含带有cs_di_*的符号,即使源代码中没有提到cs_di_*

深入挖掘(使用-DCMAKE_EXPORT_COMPILE_COMMANDS=1获取实际的构建命令),我发现我已经安装了suite-sparse。该库在/usr/local/include/cs.h处提供了一个标头,其中包含以下两个定义:

typedef struct cs_di_sparse
{
...
} cs_di ;
typedef struct cs_di_symbolic
{
...
} cs_dis ;

并定义:

#define cs cs_di
#define css CS_NAME (s)
#define CS_NAME(nm) cs_di ## nm

这意味着g2o项目将使用已安装的SuiteSparse版本(如果可用)正确生成。否则,它将使用包含的(较旧的)EXTERNAL/csparse/cs.h标头进行构建。

卸载suite-sparse后,运行您提供的命令仍然可以正常工作,所以我的收获是:

  • 您的一些翻译单元是按照包含的cs.h
  • 有些人在系统上的其他位置查看已安装的版本

要隔离这一点,请使用nm准确查看哪些对象/库具有这些符号的哪个版本,并为每个对象/库制定构建命令。

相关内容

  • 没有找到相关文章

最新更新