Ubuntu20.04安装Ceres1.14版本并测试是否成功

Ceres库的安装

一、添加源

sudo gedit /etc/apt/sources.list

将下面的源粘贴到source.list的最上方 ,保存退出

deb http://cz.archive.ubuntu.com/ubuntu trusty main universe

更新

sudo apt-get update

二、安装依赖库

sudo apt-get install liblapack-dev libsuitesparse-dev libcxsparse3.1.2 libgflags-dev 
sudo apt-get install libgoogle-glog-dev libgtest-dev

三、下载Ceres1.14版本并解压

wget ceres-solver.org/ceres-solver-1.14.0.tar.gz
tar -zxvf ceres-solver-1.14.0.tar.gz

四、编译安装

cd ceres-solver-1.14.0
mkdir build
cd build
cmake ..
make -j4
sudo make install

测试Ceres库是否安装成功

编写CMakeLists.txt

cmake_minimum_required(VERSION 3.8.0)
 
project(ceres_example)
 
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
 
find_package(Ceres REQUIRED)
 
include_directories(
  ${CERES_INCLUDE_DIRS}
)
 
add_executable(ceres_example
ceres_example.cpp)
 
target_link_libraries(ceres_example
    ${CERES_LIBRARIES}
)

ceres官网一个例子

#include <ceres/ceres.h>
 
class CostFunctor {
public:
    template <typename T>
    bool operator()(const T* const x, T* residual) const
    {
        residual[0] = 10.0 - x[0];
        return true;
    }
};
 
int main(int argc, char const* argv[])
{
    double initial_x = 5.0;
    double x = initial_x;
 
    // Build the problem.
    ceres::Problem problem;
 
    // Set up the only cost function (also known as residual). This uses
    // auto-differentiation to obtain the derivative (jacobian).
    ceres::CostFunction* cost_function = new ceres::AutoDiffCostFunction<CostFunctor, 1, 1>(new CostFunctor);
    problem.AddResidualBlock(cost_function, nullptr, &x);
 
    // Run the solver!
    ceres::Solver::Options options;
    options.linear_solver_type = ceres::DENSE_QR;
    options.minimizer_progress_to_stdout = true;
    ceres::Solver::Summary summary;
    Solve(options, &problem, &summary);
 
    std::cout << summary.BriefReport() << "\n";
    std::cout << "x : " << initial_x
              << " -> " << x << "\n";
    return 0;
}

终端输入

mkdir build
cd build
cmake ..
make

 build中生成可执行文件

终端输入

./ceres_example

输出如下:

 则ceres库安装成功。

Ceres库的卸载

Ceres只有一个库文件在"/usr/local/lib/“中,并且所有的头文件都在”/usr/local/include/ceres/"中,所以卸载Ceres库只需要将这两个文件删除即可。

sudo rm -r /usr/local/lib/cmake/Ceres
sudo rm -rf /usr/local/include/ceres /usr/local/lib/libceres.a

  • 4
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值