1
g++ --shared -fPIC -o foo.so foo.cpp
g++ main.cpp foo.so
./a.out

result:

./a.out: error while loading shared libraries: foo.so: cannot open shared object file: No such file or directory

But:

g++ --shared -fPIC -o foo.so foo.cpp
g++ main.cpp ./foo.so
./a.out

succeed

./foo.so vs foo.so, How so? Thanks!

Tiina
  • 4,285
  • 7
  • 44
  • 73
  • 1
    You can check [here](https://stackoverflow.com/questions/480764/linux-error-while-loading-shared-libraries-cannot-open-shared-object-file-no-s). There are a few solutions. I think the basic reason it fails is that when you supply the file name alone it searches in directories in the linker path and the current directory is not included in the path variable. – Paul Rooney Sep 10 '21 at 02:35

0 Answers0