前言
??????? 这篇博客解决一个通用性问题:利用cmake编译c++工作空间时,错把一些用的比较多的、比较知名的库当做“包”,导致编译错误,下面以ipopt为例。
报错 ????????安装完ipopt库后,编译自己的包报错,找不到ipopt这个“包”,报错如下: A required package was not found ... cmake/FindIPOPT.cmake:3 (pkg_check_modules)
Errors << path_tracking:check /home/bit/test/logs/path_tracking/build.check.000.log
CMake Error at /usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:419 (message):
A required package was not found
Call Stack (most recent call first):
/usr/share/cmake-3.10/Modules/FindPkgConfig.cmake:597 (_pkg_check_modules_internal)
cmake/FindIPOPT.cmake:3 (pkg_check_modules)
CMakeLists.txt:19 (find_package)
make: *** [cmake_check_build_system] Error 1
cd /home/bit/test/build/path_tracking; catkin build --get-env path_tracking | catkin env -si /usr/bin/make cmake_check_build_system; cd -
..................................................................................................................................................................................................................................................................................
Failed << path_tracking:check [ Exited with code 2 ]
Failed <<< path_tracking [ 3.1 seconds ]
[build] Summary: 8 of 9 packages succeeded.
[build] Ignored: 49 packages were skipped or are blacklisted.
[build] Warnings: None.
[build] Abandoned: None.
[build] Failed: 1 packages failed.
[build] Runtime: 11.4 seconds total.
??????? 其中:CMakeLists.txt中配置ipopt如下:
find_package(IPOPT REQUIRED) #hxz
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} ${IPOPT_LIBRARIES} ${controllib_LIBRARIES})#hxz
报错原因: ??????? ipopt是一个非线性优化库,即库文件,不是ros的package,自然不能够被当做包被找到;只要把ipopt对应的库文件在CMakeLists.txt中配置好即可
修改如下:
#find_package(IPOPT REQUIRED) #hxz
#target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} ${IPOPT_LIBRARIES} ${controllib_LIBRARIES})#hxz
target_link_libraries(${PROJECT_NAME}_node ${catkin_LIBRARIES} ${controllib_LIBRARIES} /usr/lib/libipoptamplinterface.so.1 /usr/local/lib/libipoptamplinterface.so.0 /usr/local/lib/libipoptamplinterface.so /usr/lib/libipoptamplinterface.so /usr/lib/libipopt.so.1 /usr/local/lib/libipopt.so.0 /usr/local/lib/libipopt.so /usr/lib/libipopt.so)
(1)注释掉find_package() (2)将${controllib_LIBRARIES}替换为对应的ipopt库文件,这些库文件可以通过下面命令查找:?
ldconfig -p | grep libipopt
(注:复制右边的绝对路径即可)
bit@ubuntu:~$ ldconfig -p | grep libipopt
libipoptamplinterface.so.1 (libc6,AArch64) => /usr/lib/libipoptamplinterface.so.1
libipoptamplinterface.so.0 (libc6,AArch64) => /usr/local/lib/libipoptamplinterface.so.0
libipoptamplinterface.so (libc6,AArch64) => /usr/local/lib/libipoptamplinterface.so
libipoptamplinterface.so (libc6,AArch64) => /usr/lib/libipoptamplinterface.so
libipopt.so.1 (libc6,AArch64) => /usr/lib/libipopt.so.1
libipopt.so.0 (libc6,AArch64) => /usr/local/lib/libipopt.so.0
libipopt.so (libc6,AArch64) => /usr/local/lib/libipopt.so
libipopt.so (libc6,AArch64) => /usr/lib/libipopt.so
注:ipopt安装见另一篇博客https://blog.csdn.net/BIT_HXZ/article/details/124104568
@meng
|