6

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!

Claire Huang
  • 941
  • 17
  • 27
  • 2
    What error do you get when you try to run it? That would be a big help in offering advice - it could be anything from a differing a architecture to missing libraries to incorrect assumptions about the kernel. – DrStalker May 25 '10 at 02:26
  • I've post the error message on :) – Claire Huang May 25 '10 at 02:32

3 Answers3

4

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.

Community
  • 1
  • 1
Nikolai Fetissov
  • 77,392
  • 11
  • 105
  • 164
  • Oh I see the problem...My QtCreator is for 64-bit, and the CentOS is 32 bit.... Is there anyway to set it to 32 bit in QtCreator? – Claire Huang May 25 '10 at 02:50
  • 3
    You'll need the gcc option "-m32" and change the -L option to your 32bit library path. Take a look here and see if it's useful -> http://ubuntuforums.org/showthread.php?t=265585 – shinkou May 25 '10 at 03:24
  • Thanks, that's helpful, now I'm trying to figure out how to set the compile parameter, after that this information will be helpful :) – Claire Huang May 25 '10 at 07:09
  • I've found how to set the parameter and can compile 32-bit file now. There is another problem, it seems there are some dependency on Qt so that it cannot run on a computer without Qt SDK. How can I get rid of this dependency?? – Claire Huang May 25 '10 at 23:08
  • You need to either compile your project *statically* (look for `-static` compiler flag), or pack dynamic libraries your app depends on with the app itself and play with `LD_PRELOAD_PATH` environment variable on the target machine (read `ld.so(8)` man page.) – Nikolai Fetissov May 26 '10 at 02:23
  • Thanks! I'm trying to build a static Qt now :). Hope that it will work – Claire Huang May 26 '10 at 07:54
2

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.

shinkou
  • 4,973
  • 1
  • 18
  • 28
2

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.

Gnurou
  • 7,502
  • 3
  • 20
  • 32
  • Thanks :) I know it's not a best way to run executable file from different system, however, I don't have enough permission to install Qt on CentOS, and I cannot build an executable file on it, this is the problem ><.> – Claire Huang May 25 '10 at 07:04