c++ - 无法在 qt creator (linux) 上链接共享库

标签 c++ linux qt shared-libraries qt-creator

这是我的 .pro 文件:

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

DEPENDPATH += /home/khajak/CList/linker
INCLUDEPATH += /home/khajak/CList/linker

LIBS += -L/home/khajak/CList/linker -llibCListManager
LIBS += -L/home/khajak/CList/linker -llibCommandLineEngine

这里是 /home/khajak/CList/linker 目录:

lrwxrwxrwx 1 khajak khajak     24 Mar 30 23:10 libCListManager.so -> libCListManager.so.1.0.0
lrwxrwxrwx 1 khajak khajak     24 Mar 30 23:10 libCListManager.so.1 -> libCListManager.so.1.0.0
lrwxrwxrwx 1 khajak khajak     24 Mar 30 23:10 libCListManager.so.1.0 -> libCListManager.so.1.0.0
-rwxrwxr-x 1 khajak khajak 344109 Mar 30 22:37 libCListManager.so.1.0.0
lrwxrwxrwx 1 khajak khajak     29 Mar 30 23:10 libCommandLineEngine.so -> libCommandLineEngine.so.1.0.0
lrwxrwxrwx 1 khajak khajak     29 Mar 30 23:10 libCommandLineEngine.so.1 -> libCommandLineEngine.so.1.0.0
lrwxrwxrwx 1 khajak khajak     29 Mar 30 23:10 libCommandLineEngine.so.1.0 -> libCommandLineEngine.so.1.0.0
-rwxrwxr-x 1 khajak khajak 207537 Mar 30 18:24 libCommandLineEngine.so.1.0.0
-rw-rw-r-- 1 khajak khajak    285 Mar 30 23:15 linker.pro

Qtcreator 抛出错误:

:-1: error: cannot find -llibCListManager
:-1: error: cannot find -llibCommandLineEngine

最佳答案

引用 man ld

  -l namespec
  --library=namespec<br>

Add the archive or object file specified by namespec to the list of files to link. This option may be used any number of times. If namespec is of the form :filename, ld will search the library path for a file called filename, otherwise it will search the library path for a file called libnamespec.a.

On systems which support shared libraries, ld may also search for files other than libnamespec.a. Specifically, on ELF and SunOS systems, ld will search a directory for a library called libnamespec.so before searching for one called libnamespec.a. (By convention, a ".so" extension indicates a shared library.) Note that this behavior does not apply to :filename, which always specifies a file called filename.

因此,-llibCListManager 意味着您要链接名为 liblibCListManager.so 的库。对于 libCListManager.so,正确的选项是 -lCListManager

关于c++ - 无法在 qt creator (linux) 上链接共享库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22736485/

相关文章:

c++ - 包装右值引用 lambda 时 std::async 和 std::bind 之间的区别

C++ OpenCV 图像通过套接字发送

c++ - 编译器优化创建系统调用?

c++ - QT - QFile 复制操作极其缓慢

c++ - QDialog:如何在 Windows 上启用父窗口(主窗口)的后面?

c++ - QJsonValueRef 与 QJsonValue

c - Travis CI 使用非 perl 语言安装 perl 模块

linux - 尝试在 Linux 系统上运行可执行文件时出错

linux - 检查 "cat"的输出是否不为空

qt - MapItemView 在 dataChanged 信号后不更新