I'm using Ubuntu 10.04 and Qt4.6, and I've created an executable binary file on my own computer through QtCreator.
Now I want to put my executable file on CentOS 5, but it seems that this executable file cannot run on CentOS.
The error message is
bash: ./[filename]: cannot execute binary file
Now I know this comes from 32-bits and 64-bits problem, and successfully create 32-bit exexutable file.
However, this executable file still cannot run on CentOS because of the dynamic linkage problem, it always shows that :
Error while loading shared libraries: libQtGUI.so.4: cannot open shared object file: No such file or directory
I tried to add the "-static" flag on .pro file
QMAKE_CFLAGS_RELEASE += -Os -static
QMAKE_CPPFLAGS_RELEASE += -Os -static
QMAKE_CXXFLAGS_RELEASE += -Os -static
QMAKE_CCFLAGS_RELEASE += -Os -static
however, looks like that it only generate "static binary" but not "static linked", the dependency still exists.
I also tried to add following line on .pro file:
QMAKE_LFLAGS += static
But this project cannot compile after doing this. I don't have permission to install Qt on Cent OS, how can I compile this project with static linkage so that the executable file can run independently?
Thanks for your help!
Check 64-bit vs. 32-bit - file(1)
is your friend here. Then check what libraries are missing with ldd(1)
.
Take a look at this SO question Qt static linking and deployment.
There could be a handful of reasons for your executable not being able to run. However, check the dependencies first with "ldd" to get a clue.
In general it's always a bad idea to run an executable from one distro on another. Apart from the architectural differences (32 vs 64 bits) you may also run into libraries incompatibilities, ABI changes, and other fun stuff. You can get rid of the libraries problem by compiling a static binary, but this comes with other drawbacks.
You should consider distributions as systems of their own, regardless of the fact they are all based on the Linux kernel, and compile binaries for each of those you want to support. The OpenSUSE Build Factory may help you if your goal is to provide binary packages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With