在VS2022通过WSL运行Linux项目时无法打开共享对象文件
Windows 10下VS2022通过WSL Ubuntu 20.04运行C++项目动态库加载失败的解决
问题场景
- 环境:Windows 10 + Visual Studio 2022 + WSL Ubuntu 20.04
- 已完成配置:将动态库路径添加到项目
Additional Library Search Path,并把所有.so文件加入Library Dependecies,项目构建成功 - 运行错误:
error while loading shared libraries: xxx.so: cannot open shared object file: No such file or directory - 库文件实际路径:
/home/myuser/my_ws/install/lib - 无效尝试:
- 将库路径添加到
Configuration Properties -> Debugging -> Additional Symbol Search Paths,无效果 - 手动复制
.so文件到/usr/lib/x86_64-linux-gnu可临时解决,但属于非规范操作
- 将库路径添加到
解决方法
在项目的Configuration Properties -> Debugging -> Pre-Launch Command中添加以下命令:
export LD_LIBRARY_PATH=/home/myuser/my_ws/install/lib
添加完成后重新运行项目,动态库加载问题即可解决。
内容的提问来源于stack exchange,提问作者theateist
相关产品推荐
相关产品推荐

