问题:我想使用 Google 的ceres-solver
C++ 库,但无法在其网页helloworld.cc
上运行该示例。
安装:我正在使用(全新安装)CentOS7,并按照ceres-solver
网站上的安装说明进行操作。替换apt-get
with yum
-equivalent 包,我安装了以下内容:
- 对于
g++
编译器,gcc
使用安装sudo yum install "Development Tools"
cmake
有了这些说明。- 几个图书馆
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
其次是网页上的linux指令ceres
,即
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
我看到该错误与此问题类似,但尚未收到令人满意的答案。任何帮助,将不胜感激。