ubuntu 20.04 apt install 安装的 yaml-cpp 找不到

apt install 安装的 yaml-cpp 库找不到:

检查发现:多了一个 /usr

pkg-config --cflags --libs yaml-cpp
-L/usr//usr/lib/x86_64-linux-gnu -lyaml-cpp

尝试修复这个文件: /usr/lib/x86_64-linux-gnu/pkgconfig/yaml-cpp.pc

Change this line:

libdir=${exec_prefix}//usr/lib/x86_64-linux-gnu

To this:

libdir=${exec_prefix}/lib/x86_64-linux-gnu
pkg-config --cflags --libs yaml-cpp
#  -lyaml-cpp 输出的 -lyaml-cpp 确实是正确的,但库路径没有显示出来

卸载了重新安装还是不行。

解决: 源码手动安装:

git clone https://github.com/jbeder/yaml-cpp.git
cd yaml-cpp
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON ..
make
make install

卸载现有的 libyaml-cpp0.6:

apt remove --purge libyaml-cpp0.6
apt autoremove

检验:

ls /usr/local/lib/x86_64-linux-gnu/libyaml-cpp.*
 # /usr/local/lib/x86_64-linux-gnu/libyaml-cpp.a  /usr/local/lib/x86_64-linux-gnu/libyaml-cpp.so  /usr/local/lib/x86_64-linux-gnu/libyaml-cpp.so.0.8  /usr/local/lib/x86_64-linux-gnu/libyaml-cpp.so.0.8.0

pkg-config --cflags --libs yaml-cpp
# -I/usr/local/include -L/usr/local/lib/x86_64-linux-gnu -lyaml-cpp

注意: -DBUILD_SHARED_LIBS=ON 这个用来生成 .so 共享库

CMakeLists.txt:

# 设置 yaml-cpp 的路径
set(YAML-CPP_INCLUDE_DIRS "/usr/local/include")
set(YAML-CPP_LIBRARIES "/usr/local/lib/x86_64-linux-gnu/libyaml-cpp.so")
message(STATUS "YAML-CPP Include Dir: ${YAML-CPP_INCLUDE_DIRS}")
message(STATUS "YAML-CPP Libraries: ${YAML-CPP_LIBRARIES}")

set(SRCS_COMMON sample_common.cpp sample_common.h CameraParameters.cpp CameraParameters.h)

add_executable(stereosgm_imgdir stereosgm_imgdir.cpp ${SRCS_COMMON})
target_include_directories(stereosgm_imgdir PRIVATE ${OpenCV_INCLUDE_DIRS} ${YAML-CPP_INCLUDE_DIRS})
target_link_libraries(stereosgm_imgdir sgm ${OpenCV_LIBS} ${YAML-CPP_LIBRARIES})
posted @ 2024-12-17 10:25  cold_moon  阅读(14)  评论(0编辑  收藏  举报