Can't run the executable binary on another Linux system?

I use Ubuntu 10.04 and Qt4.6, and I created an executable binary on my own computer through QtCreator.

Now I want to put my executable on CentOS 5, but it seems that this executable cannot work on CentOS.

Error message

bash: ./[filename]: cannot execute binary file 

Now I know that this comes from a 32-bit and 64-bit problem and successfully creates a 32-bit exexutable file.

However, this executable still cannot work on CentOS due to a dynamic link 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 adding the "-static" flag to the .pro file

 QMAKE_CFLAGS_RELEASE += -Os -static QMAKE_CPPFLAGS_RELEASE += -Os -static QMAKE_CXXFLAGS_RELEASE += -Os -static QMAKE_CCFLAGS_RELEASE += -Os -static 

however, it looks like it only generates “static binary”, but not “static”, the dependency still exists.

I also tried adding the following line to the .pro file:

 QMAKE_LFLAGS += static 

But this project cannot compile after that. I do not have permission to install Qt on Cent OS, how can I compile this project with static link so that the executable can work independently?

Thank you for your help!

+6
c ++ cross-platform qt qt4 qt-creator
source share
3 answers

Check out 64-bit and 32-bit - file(1) is your friend here. Then check which libraries are missing with ldd(1) .

Edit:

Take a look at this question SO static links and Qt deployment .

+4
source share

There may be several reasons why your executable file may not work. However, first check the dependencies with "ldd" to get a hint.

+2
source share

In general, it is always nice to run an executable file from one distribution to another. Besides architectural differences (32 vs 64 bit), you may also encounter library incompatibilities, ABI changes, and other fun things. You can get rid of the library problem by compiling a static binary, but this has other drawbacks.

You should consider distributions as your own systems, regardless of whether they are all based on the Linux kernel, and compile binaries for each of those that you want to support. OpenSUSE Build Factory can help you if your goal is to provide binary packages.

+2
source share

All Articles