Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run an executable binary file on another Linux System?

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!

like image 858
Claire Huang Avatar asked May 25 '10 02:05

Claire Huang


3 Answers

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

Edit:

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

like image 160
Nikolai Fetissov Avatar answered Oct 05 '22 01:10

Nikolai Fetissov


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.

like image 32
shinkou Avatar answered Oct 05 '22 00:10

shinkou


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.

like image 25
Gnurou Avatar answered Oct 05 '22 02:10

Gnurou