2017-09-17 104 views
0

我嘗試用CentOS編譯Qt項目。 This問題描述我所做的細節和 我想通過參考this與另一個glibc庫/users/my/lib64/(我無法更新/ lib64 /)。編譯:未定義的參考「clock_gettime和memcpy」用於Qt項目

這是編出來的說:

g++ ./main.o ./moc_widget.o ./widget.o \ 
    -o ./test -Wl,--rpath=/users/my/lib64 \ 
    -Wl,--rpath=/users/my/Qt/5.9.1/gcc_64/lib \ 
    -Wl,--dynamic-linker=/users/my/lib64/libc.so.6 \ 
    -Wl,--dynamic-linker=/users/my/lib64/libz.so.1 \ 
    -L/users/my/Qt/5.9.1/gcc_64/lib -lQt5Widgets \ 
    -lQt5Gui -lQt5Core -lGL -lpthread -lglib-2.0 -lrt -lX11 \ 
    -I/users/my/test/2 \ 
    -I/users/my/Qt/5.9.1/gcc_64/include \ 
    -I/users/my/Qt/5.9.1/gcc_64/include/QtWidgets \ 
    -I/users/my/Qt/5.9.1/gcc_64/include/QtCore \ 
    -I/users/my/Qt/5.9.1/gcc_64/include/QtGui 

.pro文件:

QT  += core gui 

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 

TARGET = test 
TEMPLATE = app 

DEFINES += QT_DEPRECATED_WARNINGS 

CONFIG += qt 

SOURCES += \ 
     main.cpp \ 
     widget.cpp 

HEADERS += \ 
     widget.h 

FORMS += \ 
     widget.ui 

gcc版本:6.1.0

但錯誤:

/users/my/Qt/5.9.1/gcc_64/lib/libQt5Core.so: undefined reference to `[email protected]_2.17' 
    /users/my/Qt/5.9.1/gcc_64/lib/libQt5Widgets.so: undefined reference to `[email protected]_2.14' 
    collect2 ld returned exit 1 status 

如何解決它?

+0

將你的'.pro'文件添加到問題中,看起來是一個鏈接錯誤,幷包含你的gcc版本 – saeed

+0

我很困惑你想在本地機器上編譯你的項目並將它部署到目標機器或者你想編譯項目目標machie – saeed

+0

謝謝。我修改我的問題。對不起,前者是理想的,但我不能在目標機器上運行應用程序,所以我嘗試後者。 – yaa

回答

0
g++ ./main.o ./moc_widget.o ./widget.o \ 
-o ./test -Wl,--rpath=/users/my/lib64 \ 
-Wl,--rpath=/users/my/Qt/5.9.1/gcc_64/lib \ 
-Wl,--dynamic-linker=/users/my/lib64/libc.so.6 \ 
-Wl,--dynamic-linker=/users/my/lib64/libz.so.1 \ 
-L/users/my/Qt/5.9.1/gcc_64/lib -lQt5Widgets \ 
-lQt5Gui -lQt5Core -lGL -lpthread -lglib-2.0 -lrt -lX11 \ 
-I... 

此命令行完全是假的(你不明白previous answer):只能有一個動態鏈接器,它應該是/users/my/lib64/ld-linux-x86-64.so.2,而不是libz.so.1。通過使用多個--dynamic-linker=...標誌,您只需替換先前(不正確)的設置與新的(也是不正確的)設置。

這也是假的,因爲在鏈接上指定-I...標誌沒有任何源的行是毫無意義的。

如果這個命令成功了,你最終會得到一個立即崩潰的可執行文件,因爲libz.so.1而不是動態鏈接器。

現在,您的鏈接失敗,因爲您正在執行錯誤的系統上的鏈接。您需要鏈接原始系統(您之前成功鏈接您的二進制文件的那個系統,以及具有GLIBC 2.17或更高版本的二進制文件)。然後將鏈接的可執行文件移動到目標系統。

在原來的系統,你的鏈接命令應該是這個樣子:

g++ main.o moc_widget.o widget.o -o test \ 
    -Wl,-rpath=/users/my/lib64 \ 
    -Wl,--dynamic-linker=/users/my/lib64/ld-linux-x86-64.so.2 \ 
-L... 

這兩條線上面我縮進應該是從原始的成功鏈接命令只有變化。