Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot open shared object file when run Linux project through Visual Studio 2022

I am building and running C++ project in WSL Ubuntu 20.04 through Visual Studio 2022 on Windows 10.

I included all relevant paths to project's Additional Library Search Path and all .so files to Library Dependecies and was able to build the project in VS.

However, when I run in VS I get error while loading shared libraries: xxx.so: cannot open shared object file: No such file or directory. The missing .so is located at /home/myuser/my_ws/install/lib (DIR). If I copy manually that library from DIR to /usr/lib/x86_64-linux-gnu then it can find it.

I tried adding that .so to Configuration Properties -> Debugging -> Additional Symbol Search Paths, but it didn't help

enter image description here

UPDATE

I tried adding export LD_LIBRARY_PATH=/home/myuser/my_ws/install/lib to Pre-Launch Command as suggested by @Sam Varshavchik and it worked.

enter image description here

like image 640
theateist Avatar asked Feb 19 '26 13:02

theateist


1 Answers

To load a .so library at runtime, one of the following three conditions must be met.

  1. The .so library must be located in one of the default system library locations, like /usr/lib or /usr/lib64, or various subdirectories there. Additional default system library locations are listed in /etc/ld.so.conf.

  2. The LD_LIBRARY_PATH environment variable must be set, accordingly, before running the executable that attempts to load the .so file.

  3. The executable must be linked with the -rpath or -R linker flag, specifying the directory to add to the search path, at runtime.

You can decide which approach will work the best for you, and proceed accordingly. See the ld.so(8) manual page for a complete description of the shared library loading process, and additional options.

like image 153
Sam Varshavchik Avatar answered Feb 22 '26 04:02

Sam Varshavchik