【环境】ceres库在ubantu的qt上配置

一直没找到比较好的解决静态库的问题,最后还是投降使用了动态库,记录一下!
1.版本信息
安装的是1.4,够用而且不会出现2.1版本的奇怪问题
2.安装教程

wget -c https://github.com/ceres-solver/ceres-solver/archive/refs/tags/1.14.0.zip
unzip 1.14.0.zip

进入到对应文件夹的路径下

cmake .. -DBUILD_SHARED_LIBS=ON
make 
sudo make install 

【环境】ceres库在ubantu的qt上配置_第1张图片
3.在qt中配置

#c++版本需要在14以上
CONFIG += c++14 console
#库和依赖
INCLUDEPATH += /ceres包路径/include/ceres\
								/usr/include/eigen3
#LIBS += -L/usr/local/lib -lceres
LIBS += /usr/local/lib/libceres.so

4.测试代码

#include 

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;
}
//int main()
//{
//    enum State {
//      LOST,
//      DETECTING,
//      TRACKING,
//      TEMP_LOST,
//    } tracker_state;
//    std::cout<
//}

【环境】ceres库在ubantu的qt上配置_第2张图片
计算是基本配置完成了

你可能感兴趣的:(qt,开发语言)