2014-03-29 65 views
0

這裏是我的.pro文件:無法鏈接共享上Qt創建者(Linux)的庫

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 
+2

'-llibCListManager'表示你想鏈接一個名爲'liblibCListManager.so'的庫。試試'-lCListManager'。 –

+0

@ n.m。對,就是這樣,寫一個答案,我可以接受。附:他們爲什麼要以這種方式進行鏈接? – khajvah

回答

2

引用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