0

I try to compile Qt project with CentOS. This question describe what I have done in detail and I want to do with another glibc libraries /users/my/lib64/ (I can't update /lib64/) by referring to this.

This is the compile out put:

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 file :

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 version : 6.1.0

But the error:

    /users/my/Qt/5.9.1/gcc_64/lib/libQt5Core.so: undefined reference to `clock_gettime@GLIBC_2.17'
    /users/my/Qt/5.9.1/gcc_64/lib/libQt5Widgets.so: undefined reference to `memcpy@GLIBC_2.14'
    collect2 ld returned exit 1 status

How to solve it ?

valiano
  • 16,433
  • 7
  • 64
  • 79
yaa
  • 13
  • 3
  • add your `.pro` file to question , seems a link error and include your gcc version – saeed Sep 17 '17 at 08:21
  • I'm confuse do you want to compile your project in local machine and deploy it to target machine or you want to compile project in target machie – saeed Sep 17 '17 at 08:31
  • Thanks. I modify my question. Sorry for confusing, the former is ideal, but I can't run the application in target machine, so I try the latter. – yaa Sep 17 '17 at 08:54
  • Create a simple project and build. I want to check that you can build just a simple application or not? – saeed Sep 17 '17 at 09:41
  • I made simple project, only close button, but I use Qtcreator and pick up the release project, so I don't know too much about building with cui. – yaa Sep 17 '17 at 10:17
  • could you build that sucessfully – saeed Sep 17 '17 at 10:34
  • yes, I could run it in my local PC – yaa Sep 17 '17 at 10:35
  • is there a bin folder in /users/my/Qt/5.9.1/gcc_64/ – saeed Sep 17 '17 at 10:35
  • do you want to build you project in local pc – saeed Sep 17 '17 at 10:36
  • /users/my/Qt/5.9.1/gcc_64/bin exists – yaa Sep 17 '17 at 10:38
  • Ideally, I want to build the project in my local PC and deploy it, but this project shows the error such as "GLIBC_2.12" in target PC. – yaa Sep 17 '17 at 10:43
  • I think during build process linker could not find ***.so** files in bin folder of your path you should add it to path in linux there is a method to add path in ubuntu check [this](https://askubuntu.com/questions/60218/how-to-add-a-directory-to-the-path) and add path – saeed Sep 17 '17 at 10:50
  • I apoIogize taking your time. I add /users/my/Qt/5.9.1/gcc_64/bin to PATH, but it doesn't work. – yaa Sep 17 '17 at 11:14
  • Use echo path to see and ensure you have added it ti path correctly and also run sudo ldconfig in terminal and try again – saeed Sep 17 '17 at 11:37
  • I want you to make sure that you have added path perfectly – saeed Sep 17 '17 at 11:38
  • I don't have root permission, so I can't run sudo ldconfig. Maybe root user don't add me to sudoers. I try asking him. – yaa Sep 17 '17 at 12:38

1 Answers1

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...

This command line is completely bogus (you didn't understand previous answer): there can only be one dynamic linker, and it should be /users/my/lib64/ld-linux-x86-64.so.2, and not libz.so.1. By using multiple --dynamic-linker=... flags, you are simply replacing previous (incorrect) setting with a new (also incorrect) one.

It's also bogus because specifying -I... flags on the link line without any sources is pointless.

If this command succeeded, you'd end up with an executable that would simply crash immediately, because libz.so.1 is not a dynamic linker.

Now, your link fails because you are performing the link on the wrong system. You need to link on the original system (the one where you successfully linked your binary earlier, and the one which has GLIBC 2.17 or later). And then move the linked executable to your target system.

On the original system, your link command should look something like this:

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...

The two lines I indented above should be the only change from your original successful link command.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362