关于连接库的问题

关于连接库的问题

我创建了一个连接库,叫libclass.so,我在其他程序中想使用这个库,我的方法是:
g++ -s -shared -o main main.cpp -lclass -L.

共享库文件与main.cpp在同一个目录下,编译没有问题,但是运行的时候总是提示 error loading shared libraries: libclass.so connot open shared object file: no such file or directory
从"Advanced Linux Programming"上抄来的:

When you link a program with a shared library, the linker does not put the full path to the shared library in the resulting executable. Instead, it places only the name of the shared library. When the program is actually run, the system searches for the shared library and loads it. The system searches only /lib and /usr/lib, by default. If a shared library that is linked into your program is installed outside those directories, it will not be found, and the system will refuse to run the program.

One solution to this problem is to use the -Wl, -rpath option when linking the program.
Another solution to this problem is to set the LD_LIBRARY_PATH environment variable when running the program.