繁体   English   中英

如何通过G ++使用共享库?

[英]How to use shared library via G++?

我有一个名为matrix的库,并且在我的程序中使用了一个名为test.cpp

我可以成功生成并使用静态库,但是当我想将其用作共享库时,出现以下错误:

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$

有人有什么主意吗?

最好遵循共享库的命名约定。您以错误的方式链接。

查看以下详细信息:

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM