参考: LiJiangnanBit/path_optimizer_2
感谢作者贡献的很好的开源项目,记录一下复现过程中的问题
一. 安装依赖
1. package依赖
首先 clone 下来放到 src 中,这两个 package 也需要 clone 下来放到 src 中
2. cmake 版本问题
需要 3.8 以上的版本,我的电脑是3.5的,需要先卸载,之后安装,参考我的博客:
3. eigen 版本问题
由于通过终端命令行安装的电脑里的 eigen 版本是 3.2.9 不满足要求,编译会报错:
CMake Error at cmake/OsqpEigenDependencies.cmake:12 (find_package):
Could not find a configuration file for package "Eigen3" that is compatible
with requested version "3.2.92".
The following configuration files were considered but not accepted:
/usr/lib/cmake/eigen3/Eigen3Config.cmake, version: unknown
Call Stack (most recent call first):
CMakeLists.txt:75 (include)
-- Configuring incomplete, errors occurred!
See also "/home/seivl/my_lib/osqp-eigen/build/CMakeFiles/CMakeOutput.log".
先卸载了,再安装高版本的:
- 卸载 eigen
- 添加链接描述
卸载:
sudo rm -rf /usr/include/eigen3
sudo rm -rf /usr/lib/cmake/eigen3
安装:从这里下载:eigen 下载
mkdir build
cd build
cmake ..
sudo make
sudo make install
安装在这个目录:
/usr/local/include/eigen3/
要修改到这里:
usr/local/include
执行:
sudo cp -r /usr/local/include/eigen3/Eigen /usr/local/include
4. 安装osqp和osqp-eigen
需要依赖osqp-eigen,又要首先安装osqp,没安装的话也是会编译报错:
seivl@seivl-Default-string:~/my_lib/osqp-eigen/build$ cmake ..
CMake Error at cmake/OsqpEigenDependencies.cmake:13 (find_package):
By not providing "Findosqp.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "osqp", but
CMake did not find one.
Could not find a package configuration file provided by "osqp" with any of
the following names:
osqpConfig.cmake
osqp-config.cmake
Add the installation prefix of "osqp" to CMAKE_PREFIX_PATH or set
"osqp_DIR" to a directory containing one of the above files. If "osqp"
provides a separate development package or SDK, be sure it has been
installed.
Call Stack (most recent call first):
CMakeLists.txt:75 (include)
它们的安装参考这里,很详细了:
5. gflags安装
正常编译会报错:
CMake Error at path_optimizer_2/CMakeLists.txt:27 (find_package):
By not providing "Findgflags.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "gflags", but
CMake did not find one.
Could not find a package configuration file provided by "gflags" with any
of the following names:
gflagsConfig.cmake
gflags-config.cmake
Add the installation prefix of "gflags" to CMAKE_PREFIX_PATH or set
"gflags_DIR" to a directory containing one of the above files. If "gflags"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/seivl/pnc_ws/build/CMakeFiles/CMakeOutput.log".
See also "/home/seivl/pnc_ws/build/CMakeFiles/CMakeError.log".
Makefile:870: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
亲测直接使用终端命令行安装还是会报错,需要自己下载源码安装:
编译会遇到以下错误:
[ 92%] Linking CXX shared library /home/seivl/pnc_ws/devel/lib/libpath_optimizer_2.so
/usr/bin/ld: /usr/local/lib/libgflags.a(gflags.cc.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/libgflags.a: 无法添加符号: 错误的值
collect2: error: ld returned 1 exit status
path_optimizer_2/CMakeFiles/path_optimizer_2.dir/build.make:412: recipe for target '/home/seivl/pnc_ws/devel/lib/libpath_optimizer_2.so' failed
make[2]: *** [/home/seivl/pnc_ws/devel/lib/libpath_optimizer_2.so] Error 1
CMakeFiles/Makefile2:1633: recipe for target 'path_optimizer_2/CMakeFiles/path_optimizer_2.dir/all' failed
make[1]: *** [path_optimizer_2/CMakeFiles/path_optimizer_2.dir/all] Error 2
Makefile:145: recipe for target 'all' failed
make: *** [all] Error 2
Invoking "make -j8 -l8" failed
问题解决:
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=google -G "Unix Makefiles" ../
make
sudo make install
sudo ldconfig