Linux环境变量LD_LIBRARY_PATH(指定share libraries)

本文介绍了一种解决使用自编译MySQL时遇到的clientmsyql.so文件缺失的方法。通过调整LD_LIBRARY_PATH环境变量指向正确的.so文件路径,可以避免连接MySQL实例时报错。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天在使用自己编译的MySQL时遇到了一个问题:使用自己编译的这个MySQL的mysql工具连接实例时老是报错*clientmsyql.so文件找不到,当时的连接方式为./basedir/bin/mysql ... 这样肯定就是使用自己编译的这个MySQL自带的mysql工具了。去basedir 的lib目录里面看了下明明存在那些*.so文件,那为什么会提示找不到呢?这个可能是编译的问题了吧(自己也不太清楚具体哪个地方没弄好,别人编译的),总之就是他不会去basedir的lib目录里面去找这些*.so文件。为了验证这点,直接使用mysql连接实例(因为机器上还装了其他版本的mysql,已经在环境变量PATH里面设置)可以成功。

那么有什么方式可以显示的告诉mysql去哪里找这些*.so文件么?起初我很2的在PATH里面制定了这些so文件的路径,结果发现不起作用,后来才知道PATH这个环境变量是对可执行文件起作用的。真正要用的是LD_LIBRARY_PATH这个环境变量。它才是linux中显示的指定去找share libraries文件的环境变量!查了下这个环境变量的用法,发现这篇文章写得比较实在:我们应该尽量少用这个环境变量,它的主要目的不是用来给一个需要稳定运行的程序显示的指定它要去哪里找它需要的share libraries,而是用来测试一些新的share libraries,比如你新开发了一些share libraries,你不想急着覆盖旧的,那么你可以临时用LD_LIBRARY_PATH指定这些新share libraries的路径。为什么说不建议给一个长期需要运行程序用LD_LIBRARY_PATH来指定share libraries呢?因为这个不是很安全吧,哪天无意被别人修改了那不就惨了,因为你要知道LD_LIBRARY_PATH是一个全局的环境变量,别的程序也可以用的。


附:

linux中怎么更改环境变量?比如PATH=${PATH}:/path,个人喜欢用${}这样应该是最安全的,防止$解释的时候将后面的一长串全部当做变量名。

交叉编译不能执行怎么办xy-shiqi@xyshiqi-vmware:~/ros2_ws/src/only-navigaton$ cd ~/ros2_ws rm -rf build_arm install_arm log xy-shiqi@xyshiqi-vmware:~/ros2_ws$ unset LD_LIBRARY_PATH xy-shiqi@xyshiqi-vmware:~/ros2_ws$ source /opt/poky/3.1.20/environment-setup-aarch64-poky-linux source /opt/ros/humble/setup.bash xy-shiqi@xyshiqi-vmware:~/ros2_ws$ source /opt/poky/3.1.20/environment-setup-aarch64-poky-linux Your environment is misconfigured, you probably need to 'unset LD_LIBRARY_PATH' but please check why this was set in the first place and that it's safe to unset. The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set. For more references see: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80 http://xahlee.info/UnixResource_dir/_/ldpath.html xy-shiqi@xyshiqi-vmware:~/ros2_ws$ source /opt/poky/3.1.20/environment-setup-aarch64-poky-linux Your environment is misconfigured, you probably need to 'unset LD_LIBRARY_PATH' but please check why this was set in the first place and that it's safe to unset. The SDK will not operate correctly in most cases when LD_LIBRARY_PATH is set. For more references see: http://tldp.org/HOWTO/Program-Library-HOWTO/shared-libraries.html#AEN80 http://xahlee.info/UnixResource_dir/_/ldpath.html xy-shiqi@xyshiqi-vmware:~/ros2_ws$ source /opt/ros/humble/setup.bash xy-shiqi@xyshiqi-vmware:~/ros2_ws$ colcon build \ --build-base build_arm \ --install-base install_arm \ --merge-install \ --cmake-args \ -DCMAKE_TOOLCHAIN_FILE=/opt/poky/3.1.20/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake Starting >>> only-navigaton --- stderr: only-navigaton CMake Error at /opt/ros/humble/share/ament_cmake/cmake/ament_cmake_export_dependencies-extras.cmake:21 (find_package): By not providing "Findament_cmake_export_interfaces.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "ament_cmake_export_interfaces", but CMake did not find one. Could not find a package configuration file provided by "ament_cmake_export_interfaces" with any of the following names: ament_cmake_export_interfacesConfig.cmake ament_cmake_export_interfaces-config.cmake Add the installation prefix of "ament_cmake_export_interfaces" to CMAKE_PREFIX_PATH or set "ament_cmake_export_interfaces_DIR" to a directory containing one of the above files. If "ament_cmake_export_interfaces" provides a separate development package or SDK, be sure it has been installed. Call Stack (most recent call first): /opt/ros/humble/share/ament_cmake/cmake/ament_cmakeConfig.cmake:41 (include) CMakeLists.txt:31 (find_package) --- Failed <<< only-navigaton [0.54s, exited with code 1] Summary: 0 packages finished [0.76s] 1 package failed: only-navigaton 1 package had stderr output: only-navigaton xy-shiqi@xyshiqi-vmware:~/ros2_ws$
最新发布
07-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值