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

一直没找到比较好的解决静态库的问题,最后还是投降使用了动态库,记录一下!


1.报错

后面配自己电脑的时候又出现一些其他错误,9月26日补更:

1.1 TBB

CMake Error at cmake/FindTBB.cmake:434 (file):
  file STRINGS file "/usr/local/include/tbb/tbb_stddef.h" cannot be read.
Call Stack (most recent call first):
  cmake/FindSuiteSparse.cmake:309 (find_package)
  CMakeLists.txt:282 (find_package)

可以先检查一下自己的TBB是否有tbb_stddef.h文件(一般是安装在/usr/local/include)

ls  /usr/local/include/tbb/tbb_stddef.h

如果没有的话

cp /usr/local/include/tbb/version.h  /usr/local/include/tbb/tbb_stddef.h

1.2 undefined reference to `typeinfo for testing::Test’

将cmakelist.txt修改为

option (WITH_GTEST "Use Google Test" OFF)

1.3 glog版本

google::kLogSiteUninitialized在新版本被移除了,如果出现了一下报错

undefine reference to google::kLogSiteUninitialized 

解决办法就是
(1)先行卸载当前版本

sudo apt-get remove libgoogle-glog-dev
sudo rm -rf /usr/local/include/glog/
sudo rm -rf /usr/local/lib/libglog*

(2)下载旧版本

git clone https://github.com/google/glog.git
cd glog/
git checkout v0.5.0-rc2
mkdir build && cd build
cmake ..
sudo make -j12 install

2.配置

2.1.版本信息

安装的是1.4,够用而且不会出现2.1版本的奇怪问题

2.2 安装教程

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

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 

请添加图片描述

3.配置

都需要根据自己路径去更改

3.1 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

3.2 VScode

.vscode/c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/home/eveing/DL/vision/computerVison/ceres/ceres-solver-1.14.0/include/ceres",
                "/usr/include/eigen3"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c17",
            "cppStandard": "c++14",
            "intelliSenseMode": "linux-clang-x64"
        }
    ],
    "version": 4
}

.vscode/tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
    {
    "label": "build",
    "type": "shell",
    "command": "g++",
    "args": ["-g", "${file}",
	 "-o", "${fileBasenameNoExtension}.out",
	
	"-I","/usr/local/include/gflags",
	"-L","/usr/local/lib",
	"-l","ceres",
	"-I","/usr/local/include/glog",
	"-lglog",
	"-std=c++17"
	]
    }
    ]
   }

4.测试代码

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

请添加图片描述
在这里插入图片描述

算是基本配置完成了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值