如何通过 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
相关文章:
- 是否可以通过C++扩展强制多个python进程共享同一内存
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- Linux 可执行文件通过 dlopen 在emplace_back崩溃打开共享库
- 尝试通过共享指针使用变量时读取访问冲突
- 通过cMake使用具有自定义文件扩展名的共享库
- 如何通过指向元组的共享指针删除对象
- 通过require在不同的Lua状态之间共享全局变量
- 通过 mmap-ed 共享内存传递可变长度 C 字符串
- 矩阵矢量产品 CUDA 通过平铺和共享内存提高性能
- 通过 Boost Python 在C++对象之间传递共享指针的隔离错误
- 通过为每个线程独占使用对象(不在线程之间共享)是保护该类的成员函数所必需的
- <T>通过引用传输向量<shared_ptr>而不绕过共享语义
- 如何通过更好的性能传递和共享共享的所有权
- 如何通过另一个类将共享指针传递给一个类?
- 多态性和共享_ptr通过引用传递
- C++ 如何通过标头正确公开共享库
- 通过线程共享 std::指针的矢量
- 如何通过共享_ptr向量迭代
- 通过引用返回共享对象是否安全"std::lock_guard<mutex>"?
- 如何通过文件映射对象重新映射共享内存的视图?