问题:
我想将Google的ceres-solver库用于C++,但无法在its webpage上运行helloworld.cc示例。

安装:
我正在使用(全新安装)CentOS7,并且正在按照ceres-solver website上的安装说明进行操作。我使用等效于apt-get的软件包替换了yum,安装了以下内容:

  • 对于g++编译器,使用gcc安装了sudo yum install "Development Tools"
  • cmakethese instructions
  • 一些带有sudo yum install glog-devel atlas-devel gflags-devel eigen3-devel suitesparse-devel blas-devel lapack-devel的库
  • 在一个新文件夹中,我使用
  • 下载了tar.gz文件。
    wget http://ceres-solver.org/ceres-solver-1.14.0.tar.gz
    

    后面是ceres网页上的linux instructions,即
    mkdir ceres-bin
    cd ceres-bin
    sudo cmake ../ceres-solver-1.14.0
    sudo make -j3
    sudo make test
    sudo make install
    

    终端输出:
    下面是上述代码的简要输出。如果可以提供更多详细信息,则可以粘贴完整的日志。
  • 运行cmake:
  • $ cmake ../ceres-solver-1.14.0
    -- The C compiler identification is GNU 4.8.5
    -- The CXX compiler identification is GNU 4.8.5
    -- Check for working C compiler: /usr/bin/cc
    -- Check for working C compiler: /usr/bin/cc -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Detecting C compile features
    -- Detecting C compile features - done
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Detected Ceres version: 1.14.0 from /home/opc/ceres-installer/ceres-solver-1.14.0/include/ceres/version.h
    -- Detected non-Debian/Arch-based 64-bit Linux distribution. Defaulting to library install directory: lib. You can override this by specifying LIB_SUFFIX.
    -- No preference for use of exported Eigen CMake configuration set, and no hints for include directory provided. Defaulting to preferring an installed/exported Eigen CMake configuration if available.
    -- Found installed version of Eigen: /usr/share/eigen3
    -- Found Eigen: /usr/include/eigen3 (found version "3.3.4")
    -- Found Eigen version 3.3.4: /usr/include/eigen3
    -- Enabling use of Eigen as a sparse linear algebra library.
    
    ... [More log statements] ...
    
    -- Building Ceres as a static library.
    -- No build type specified; defaulting to CMAKE_BUILD_TYPE=Release.
    -- Creating configured Ceres config.h output directory: /home/opc/ceres-installer/ceres-bin/config/ceres/internal
    -- Enabling CERES_USE_EIGEN_SPARSE in Ceres config.h
    -- Enabling CERES_USE_OPENMP in Ceres config.h
    -- Enabling CERES_HAVE_PTHREAD in Ceres config.h
    -- Enabling CERES_HAVE_RWLOCK in Ceres config.h
    -- Enabling CERES_TR1_UNORDERED_MAP in Ceres config.h
    -- Enabling CERES_TR1_MEMORY_HEADER in Ceres config.h
    -- Enabling CERES_TR1_SHARED_PTR in Ceres config.h
    -- Build the examples.
    -- Configuring done
    -- Generating done
    -- Build files have been written to: /home/opc/ceres-installer/ceres-bin
    
  • 运行make install后的尾巴输出:
  • $ sudo make install
    Install the project...
    -- Install configuration: "Release"
    -- Installing: /usr/local/include/ceres/autodiff_cost_function.h
    -- Installing: /usr/local/include/ceres/autodiff_local_parameterization.h
    -- Installing: /usr/local/include/ceres/c_api.h
    -- Installing: /usr/local/include/ceres/ceres.h
    
    ... [Similar statements] ...
    
    -- Installing: /usr/local/include/ceres/internal/scoped_ptr.h
    -- Installing: /usr/local/include/ceres/internal/variadic_evaluate.h
    -- Installing: /usr/local/include/ceres/internal/config.h
    -- Installing: /usr/local/lib64/cmake/Ceres/CeresTargets.cmake
    -- Installing: /usr/local/lib64/cmake/Ceres/CeresTargets-release.cmake
    -- Installing: /usr/local/lib64/cmake/Ceres/CeresConfig.cmake
    -- Installing: /usr/local/lib64/cmake/Ceres/CeresConfigVersion.cmake
    -- Installing: /usr/local/lib64/cmake/Ceres/FindEigen.cmake
    -- Installing: /usr/local/lib64/cmake/Ceres/FindGlog.cmake
    -- Installing: /usr/local/lib64/cmake/Ceres/FindGflags.cmake
    -- Installing: /usr/local/lib64/libceres.a
    

    g++错误:
    当我尝试使用以下命令运行 helloworld.cc 文件时
    g++ helloworld.cc -I /usr/include/eigen3
    

    然后我得到以下错误:
    /tmp/cc8xntFU.o: In function `main':
    helloworld.cc:(.text+0xd4): undefined reference to `ceres::Problem::Problem()'
    helloworld.cc:(.text+0x119): undefined reference to `ceres::Problem::AddResidualBlock(ceres::CostFunction*, ceres::LossFunction*, double*)'
    helloworld.cc:(.text+0x13e): undefined reference to `ceres::Solver::Summary::Summary()'
    helloworld.cc:(.text+0x15b): undefined reference to `ceres::Solve(ceres::Solver::Options const&, ceres::Problem*, ceres::Solver::Summary*)'
    helloworld.cc:(.text+0x171): undefined reference to `ceres::Solver::Summary::BriefReport() const'
    helloworld.cc:(.text+0x22c): undefined reference to `ceres::Problem::~Problem()'
    helloworld.cc:(.text+0x288): undefined reference to `ceres::Problem::~Problem()'
    /tmp/cc8xntFU.o: In function `ceres::AutoDiffCostFunction<CostFunctor, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::AutoDiffCostFunction(CostFunctor*)':
    helloworld.cc:(.text._ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC2EPS1_[_ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC5EPS1_]+0xb1): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
    helloworld.cc:(.text._ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC2EPS1_[_ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC5EPS1_]+0xbd): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC2EPS1_[_ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC5EPS1_]+0xe3): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC2EPS1_[_ZN5ceres20AutoDiffCostFunctionI11CostFunctorLi1ELi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EEC5EPS1_]+0xef): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    /tmp/cc8xntFU.o: In function `std::string* google::MakeCheckOpString<int, int>(int const&, int const&, char const*)':
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x24): undefined reference to `google::base::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x4b): undefined reference to `google::base::CheckOpMessageBuilder::ForVar2()'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x66): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x75): undefined reference to `google::base::CheckOpMessageBuilder::~CheckOpMessageBuilder()'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiiEEPSsRKT_RKT0_PKc]+0x89): undefined reference to `google::base::CheckOpMessageBuilder::~CheckOpMessageBuilder()'
    /tmp/cc8xntFU.o: In function `std::string* google::MakeCheckOpString<int, ceres::DimensionType>(int const&, ceres::DimensionType const&, char const*)':
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc]+0x24): undefined reference to `google::base::CheckOpMessageBuilder::CheckOpMessageBuilder(char const*)'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc]+0x4b): undefined reference to `google::base::CheckOpMessageBuilder::ForVar2()'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc]+0x66): undefined reference to `google::base::CheckOpMessageBuilder::NewString()'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc]+0x75): undefined reference to `google::base::CheckOpMessageBuilder::~CheckOpMessageBuilder()'
    helloworld.cc:(.text._ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc[_ZN6google17MakeCheckOpStringIiN5ceres13DimensionTypeEEEPSsRKT_RKT0_PKc]+0x89): undefined reference to `google::base::CheckOpMessageBuilder::~CheckOpMessageBuilder()'
    /tmp/cc8xntFU.o: In function `ceres::internal::AutoDiff<CostFunctor, double, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0>::Differentiate(CostFunctor const&, double const* const*, int, double*, double**)':
    helloworld.cc:(.text._ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_[_ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_]+0x8c): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int, google::CheckOpString const&)'
    helloworld.cc:(.text._ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_[_ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_]+0x98): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_[_ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_]+0xa4): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_[_ZN5ceres8internal8AutoDiffI11CostFunctordLi1ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0ELi0EE13DifferentiateERKS2_PKPKdiPdPSA_]+0x33b): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    /tmp/cc8xntFU.o: In function `void ceres::internal::Make1stOrderPerturbation<ceres::Jet<double, 1>, double, 1>(int, double const*, ceres::Jet<double, 1>*)':
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0x45): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0x56): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0x9b): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0xcd): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0xde): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0x123): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0x1dd): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_[_ZN5ceres8internal24Make1stOrderPerturbationINS_3JetIdLi1EEEdLi1EEEviPKT0_PT_]+0x1fa): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    /tmp/cc8xntFU.o: In function `void ceres::internal::Take0thOrderPart<ceres::Jet<double, 1>, double*>(int, ceres::Jet<double, 1> const*, double*)':
    helloworld.cc:(.text._ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_[_ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_]+0x45): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
    helloworld.cc:(.text._ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_[_ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_]+0x56): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_[_ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_]+0x9b): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_[_ZN5ceres8internal16Take0thOrderPartINS_3JetIdLi1EEEPdEEviPKT_T0_]+0xf4): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    /tmp/cc8xntFU.o: In function `void ceres::internal::Take1stOrderPart<ceres::Jet<double, 1>, double, 0, 1>(int, ceres::Jet<double, 1> const*, double*)':
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0x57): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0x6b): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0xb9): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0xf1): undefined reference to `google::LogMessageFatal::LogMessageFatal(char const*, int)'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0x105): undefined reference to `google::LogMessage::stream()'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0x14d): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0x205): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    helloworld.cc:(.text._ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_[_ZN5ceres8internal16Take1stOrderPartINS_3JetIdLi1EEEdLi0ELi1EEEviPKT_PT0_]+0x225): undefined reference to `google::LogMessageFatal::~LogMessageFatal()'
    collect2: error: ld returned 1 exit status
    

    我看到错误类似于this question,但没有收到满意的答案。任何帮助,将不胜感激。

    最佳答案

    您需要链接到ceres求解器。

    g++ helloworld.cc -I / usr / include / eigen3 \

    仅编译helloworld,但不告诉编译器在哪里可以找到ceres求解器的 header 和已编译的库。

    关于c++ - 在centOS7上安装ceres-solver并使helloworld.cc运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57696125/

    10-13 02:58