0

I have a library that named matrix and used in my program that named test.cpp.

I can generate and use static library successfully, but when I want to use it as a shared library, I receive the following error :

ap1019@sharifvm:~/the03-copy$ ls
matrix.cpp  matrix.h  test.cpp
ap1019@sharifvm:~/the03-copy$ g++ -c matrix.cpp
ap1019@sharifvm:~/the03-copy$ g++ -shared -Wl,-soname,matrix.so -o matrix.so matrix.o
ap1019@sharifvm:~/the03-copy$ ls
matrix.cpp  matrix.h  matrix.o  matrix.so  test.cpp
ap1019@sharifvm:~/the03-copy$ g++ test.cpp matrix.so
ap1019@sharifvm:~/the03-copy$ ./a.out
./a.out: error while loading shared libraries: matrix.so: cannot open shared object file: No such file or directory
ap1019@sharifvm:~/the03-copy$

Does anyone have any idea?

Ebrahim Ghasemi
  • 5,850
  • 10
  • 52
  • 113

1 Answers1

1

It is better to follow the naming convention for shared libraries.You are linking in a wrong manner.

Check out following for details:

g++ -L/home/username/matrix -Wall -o test test.cpp -lmatrix

http://www.cprogramming.com/tutorial/shared-libraries-linux-gcc.html

adnan kamili
  • 8,967
  • 7
  • 65
  • 125
  • 1
    Yes, they do - C++ adds to C in OOPS - linking and other stuff is almost same – adnan kamili Apr 18 '15 at 11:10
  • So I generate `.so` file as I generated in the question, and when I want to use it, I must to use the command that you said in your answer, right? – Ebrahim Ghasemi Apr 18 '15 at 11:15
  • 1
    Check following http://stackoverflow.com/questions/1305266/how-to-link-to-a-shared-library-without-lib-prefix-in-a-different-directory – adnan kamili Apr 18 '15 at 11:18