ceres 使用时链接报错

编译成功后出现:

/usr/local/lib/libceres.a(visibility_based_preconditioner.cc.o):在函数‘ceres::internal::VisibilityBasedPreconditioner::ComputeBlockPairsInPreconditioner(ceres::internal::CompressedRowBlockStructure const&)’中:
visibility_based_preconditioner.cc:(.text+0xd28):对‘google::kLogSiteUninitialized’未定义的引用
visibility_based_preconditioner.cc:(.text+0xdf0):对‘google::InitVLOG3__(int**, int*, char const*, int)’未定义的引用

解决方法:
在Cmakelists.txt中,target_link_libraries 里将 ${CERES_LIBRARIES} 调整到 ${GLOG_LIBRARIES} 之前,即:

target_link_libraries(${PROJECT_NAME}
  ${catkin_LIBRARIES}
  ${OpenCV_LIBS}
  ${EIGEN3_LIBS}
  ${PCL_LIBRARIES}
  ${CERES_LIBRARIES}
  ${GLOG_LIBRARIES}
)
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
Ceres Solver是一个开源的C++库,用于解决非线性最小二乘问题。它可以用于各种应用领域,如计算机视觉、机器人、三维重建等。以下是Ceres Solver的简单使用步骤: 1. 安装Ceres Solver:可以从官网下载源代码,然后编译安装。 2. 定义问题:首先需要定义一个问题对象,该对象包含要优化的参数、残差函数和权重等信息。 3. 定义残差函数:残差函数是实际值和理论值之间的差异,需要实现该函数并传递给问题对象。 4. 设置求解选项:设置求解器的选项,例如最大迭代次数、收敛阈值等。 5. 求解问题:调用Ceres Solver的求解器函数来求解问题。 下面是一个简单的示例代码,演示如何使用Ceres Solver来解决一个非线性最小二乘问题: ```c++ #include "ceres/ceres.h" struct CostFunctor { template <typename T> bool operator()(const T* const x, T* residual) const { residual[0] = T(10.0) - x[0]; return true; } }; int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); // 初始化问题 ceres::Problem problem; // 添加参数 double x = 0.5; problem.AddResidualBlock( new ceres::AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor), nullptr, &x); // 设置求解选项 ceres::Solver::Options options; options.max_num_iterations = 100; options.linear_solver_type = ceres::DENSE_QR; options.minimizer_progress_to_stdout = true; // 求解问题 ceres::Solver::Summary summary; ceres::Solve(options, &problem, &summary); std::cout << summary.FullReport() << std::endl; std::cout << "x : " << x << std::endl; return 0; } ``` 在这个例子中,我们定义了一个CostFunctor结构体,它包含一个operator()函数,该函数计算实际值和理论值之间的差异。在main函数中,我们首先初始化了一个问题对象,然后添加了一个参数x和一个残差函数。接下来,我们设置了求解选项,并调用了Ceres Solver的求解器函数来求解问题。最后,输出结果并返回0。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值