Cannot run an executable binary file on another Linux System? - c++

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).
Edit:
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.

Related

exe file won't run on other devices [duplicate]

I have been working on a project (a game to be specific) and I feel that I should start over with different libraries. So when doing this I reinstalled Code::Blocks and setup my new libraries and includes.
But as of now Im having a problem starting u[ my new project to test if all of the includes work. This problem is: libstdc++-6.dll was not found. At first i wondered if I could just find this file online, but its nowhere to be found(or at least the many places I have searched...) Soon after, I tried loading up my old project, and the same problem happened again(wierd... ._.) I was thinking its maybe my compiler, so I used my older compiler and it did the same thing! At this moment I held the problem off for tomorrow(which is today)
So my question is: If anyone else had this problem, how would you solve it?
Im using Code::Blocks with MinGW as the compiler on Windows Vista 32 bit.
*****EDIT*****
Here are the Build options in my project. Note that these are the settings in the Project, not the global compiler:
In (project name)->Compiler settings->Otehr options:
(I use // to seperate the commands)
-mthreads//
-fmessage-length=0//
-fexceptions//
-fident//
In (project name)->Compiler settings->#define:
WIN32//
_WINDOWS//
In (project name)->Linker settings->Other linker options:
-static-libstdc++//
-static-libgcc//
-Wl,--enable-auto-image-base//
-Wl,--add-stdcall-alias//
-Wl,--enable-auto-import//
In linker->link libraries i have various links to files with a .a extension, these files include Bullet PHysics, Ogre3D, and SFML
In the search directories i have links to the MinGW/bin, and the MinGW/lib directories, along with other links to different libraries.
My Compiler is MinGW, a GNU GCC compiler for windows 32 bit. and the IDE is Codeblocks. Also note that in Debug and Release settings on the project, there is nothing.
Most of these setings are also pieces that i got from the Ogre3D Application setup tutorial if that is of any help.
If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I've found this approach the quickest and cleanest solution to creating Windows binaries.
As far as I know, this is the C++ Runtime Library. So it depends on the compiler you use to create your program (A new version will include some C++0x stuff, an older version will probably not for instance. It depends of the compiler and of its version).
If you use MinGW then you should use the libstdc++-6.dll found into the folder of this compiler. MinGW/bin folder should be the place to search for it on your computer.
If you copy this file in the same directory as your executable, it should be OK.
Simply removing libstdc++-6.dll.a \ libstdc++.dll.a from the mingw directory fixes this.
I tried using the flag -static-libstdc++ but this did not work for me.
I found the solution in: http://ghc.haskell.org/trac/ghc/ticket/4468#
This error also occurred when I compiled with MinGW using gcc with the following options:
-lstdc++ -lm, rather than g++
I did not notice these options, and added: -static-libgcc -static-libstdc++
I still got the error, and finally realized I was using gcc, and changed the compiler to g++ and removed -stdc++ and -lm, and everything linked fine.
(I was using LINK.c rather than LINK.cpp... use make -pn | less to see what everything does!)
I don't know why the previous author was using gcc with -stdc++. I don't see any reason not to use g++ which will link with stdc++ automatically... and as far as I know, provide other benefits (it is the c++ compiler after all).
useful to windows users who use eclipse for c/c++ but run *.exe file and get an error: "missing libstdc++6.dll"
4 ways to solve it
Eclipse ->"Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" -> "MinGW C++ Linker" -> "Misscellaneous" -> "Linker flags" (add '-static' to it)
Add '{{the path where your MinGW was installed}}/bin' to current user environment variable - "Path" in Windows, then reboot eclipse, and finally recompile.
Add '{{the path where your MinGW was installed}}/bin' to Windows environment variable - "Path", then reboot eclipse, and finally recompile.
Copy the file "libstdc++-6.dll" to the path where the *.exe file is running, then rerun. (this is not a good way)
Note: the file "libstdc++-6.dll" is in the folder '{{the path where your MinGW was installed}}/bin'
I use Eclipse under Fedora 20 with MinGW for cross compile.
Use these settings and the program won't ask for libstdc++-6.dll any more.
Project type - Cross GCC
Cross Settings
Prefix: x86_64-w64-mingw32-
Path: /usr/bin
Cross GCC Compiler
Command: gcc
All Options:
-I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Compiler
Command: g++
All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Linker
Command: g++ -static-libstdc++ -static-libgcc
All Options: -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/bin
Library search path (-L):
/usr/x86_64-w64-mingw32/sys-root/mingw/lib
/usr/x86_64-w64-mingw32/sys-root/mingw/bin
I just had this issue.. I just added the MinGW\bin directory to the path environment variable, and it solved the issue.
I placed the libstdc++-6.dll file in the same folder where exe file is generated.
You only need to add your "mingw-install-directory"/bin/ to your Path in your System environment variables ... that's it !!
I had same problem. i fixed it. i was using Codeblocks and i save my .cpp file on desktop instead of saving it in Codeblocks file where MinGW is located. So i copied all dll files from MinGW>>bin folder to where my .cpp file was saved.
You can also copy the dll files in the directory of your exe file
I had this problem too. I was compiling in command prompt and used the flag -static.
My command before:
"g++ test.cpp -o test.exe"
and afterwards:
"g++ test.cpp -o test.exe -static"
I had the same problem and I solved it by running the compiled exe as an administrator.

C++ windows executable compiled with Linux needs additional DLL [duplicate]

I have been working on a project (a game to be specific) and I feel that I should start over with different libraries. So when doing this I reinstalled Code::Blocks and setup my new libraries and includes.
But as of now Im having a problem starting u[ my new project to test if all of the includes work. This problem is: libstdc++-6.dll was not found. At first i wondered if I could just find this file online, but its nowhere to be found(or at least the many places I have searched...) Soon after, I tried loading up my old project, and the same problem happened again(wierd... ._.) I was thinking its maybe my compiler, so I used my older compiler and it did the same thing! At this moment I held the problem off for tomorrow(which is today)
So my question is: If anyone else had this problem, how would you solve it?
Im using Code::Blocks with MinGW as the compiler on Windows Vista 32 bit.
*****EDIT*****
Here are the Build options in my project. Note that these are the settings in the Project, not the global compiler:
In (project name)->Compiler settings->Otehr options:
(I use // to seperate the commands)
-mthreads//
-fmessage-length=0//
-fexceptions//
-fident//
In (project name)->Compiler settings->#define:
WIN32//
_WINDOWS//
In (project name)->Linker settings->Other linker options:
-static-libstdc++//
-static-libgcc//
-Wl,--enable-auto-image-base//
-Wl,--add-stdcall-alias//
-Wl,--enable-auto-import//
In linker->link libraries i have various links to files with a .a extension, these files include Bullet PHysics, Ogre3D, and SFML
In the search directories i have links to the MinGW/bin, and the MinGW/lib directories, along with other links to different libraries.
My Compiler is MinGW, a GNU GCC compiler for windows 32 bit. and the IDE is Codeblocks. Also note that in Debug and Release settings on the project, there is nothing.
Most of these setings are also pieces that i got from the Ogre3D Application setup tutorial if that is of any help.
If you are using MingW to compile C++ code on Windows, you may like to add the options -static-libgcc and -static-libstdc++ to link the C and C++ standard libraries statically and thus remove the need to carry around any separate copies of those. Version management of libraries is a pain in Windows, so I've found this approach the quickest and cleanest solution to creating Windows binaries.
As far as I know, this is the C++ Runtime Library. So it depends on the compiler you use to create your program (A new version will include some C++0x stuff, an older version will probably not for instance. It depends of the compiler and of its version).
If you use MinGW then you should use the libstdc++-6.dll found into the folder of this compiler. MinGW/bin folder should be the place to search for it on your computer.
If you copy this file in the same directory as your executable, it should be OK.
Simply removing libstdc++-6.dll.a \ libstdc++.dll.a from the mingw directory fixes this.
I tried using the flag -static-libstdc++ but this did not work for me.
I found the solution in: http://ghc.haskell.org/trac/ghc/ticket/4468#
This error also occurred when I compiled with MinGW using gcc with the following options:
-lstdc++ -lm, rather than g++
I did not notice these options, and added: -static-libgcc -static-libstdc++
I still got the error, and finally realized I was using gcc, and changed the compiler to g++ and removed -stdc++ and -lm, and everything linked fine.
(I was using LINK.c rather than LINK.cpp... use make -pn | less to see what everything does!)
I don't know why the previous author was using gcc with -stdc++. I don't see any reason not to use g++ which will link with stdc++ automatically... and as far as I know, provide other benefits (it is the c++ compiler after all).
useful to windows users who use eclipse for c/c++ but run *.exe file and get an error: "missing libstdc++6.dll"
4 ways to solve it
Eclipse ->"Project" -> "Properties" -> "C/C++ Build" -> "Settings" -> "Tool Settings" -> "MinGW C++ Linker" -> "Misscellaneous" -> "Linker flags" (add '-static' to it)
Add '{{the path where your MinGW was installed}}/bin' to current user environment variable - "Path" in Windows, then reboot eclipse, and finally recompile.
Add '{{the path where your MinGW was installed}}/bin' to Windows environment variable - "Path", then reboot eclipse, and finally recompile.
Copy the file "libstdc++-6.dll" to the path where the *.exe file is running, then rerun. (this is not a good way)
Note: the file "libstdc++-6.dll" is in the folder '{{the path where your MinGW was installed}}/bin'
I use Eclipse under Fedora 20 with MinGW for cross compile.
Use these settings and the program won't ask for libstdc++-6.dll any more.
Project type - Cross GCC
Cross Settings
Prefix: x86_64-w64-mingw32-
Path: /usr/bin
Cross GCC Compiler
Command: gcc
All Options:
-I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Compiler
Command: g++
All Options: -I/usr/x86_64-w64-mingw32/sys-root/mingw/include -O3
-Wall -c -fmessage-length=0
Includes: /usr/x86_64-w64-mingw32/sys-root/mingw/include
Cross G++ Linker
Command: g++ -static-libstdc++ -static-libgcc
All Options: -L/usr/x86_64-w64-mingw32/sys-root/mingw/lib -L/usr/x86_64-w64-mingw32/sys-root/mingw/bin
Library search path (-L):
/usr/x86_64-w64-mingw32/sys-root/mingw/lib
/usr/x86_64-w64-mingw32/sys-root/mingw/bin
I just had this issue.. I just added the MinGW\bin directory to the path environment variable, and it solved the issue.
I placed the libstdc++-6.dll file in the same folder where exe file is generated.
You only need to add your "mingw-install-directory"/bin/ to your Path in your System environment variables ... that's it !!
I had same problem. i fixed it. i was using Codeblocks and i save my .cpp file on desktop instead of saving it in Codeblocks file where MinGW is located. So i copied all dll files from MinGW>>bin folder to where my .cpp file was saved.
You can also copy the dll files in the directory of your exe file
I had this problem too. I was compiling in command prompt and used the flag -static.
My command before:
"g++ test.cpp -o test.exe"
and afterwards:
"g++ test.cpp -o test.exe -static"
I had the same problem and I solved it by running the compiled exe as an administrator.

Library link error when starting Windows application compiled with MinGW on another computer

I wrote a simple HelloWorld console application and compiled it on Windows 7 with MinGW compiler using one of these commands:
gcc -Wall -pedantic Hello.c -o Hello.exe
g++ -Wall -pedantic Hello.cpp -o Hello.exe
However the compiler links some own dynamic libraries into the app and when i copy the executable into another computer with Windows 7, which does not have MinGW installed, i'm getting missing library error. On Linux this problem is solved by package system, which automatically installs all needed libs, but in Windows you surely don't want to tell your users to install MinGW in order to run your program.
So my question is: How do i link all libraries properly and what else do i have to do to make my application run independently?
Although i believe, this must be a fundamental problem to all Windows programmers, i have been unable to find any answers on the internet (maybe i just don't know how and what to search).
It was in the FAQ at some stage, but now I seem to find it only on this page:
Why I get an error about missing libstdc++-6.dll file when running my program?
GCC4 dynamically link to libgcc and libstdc++ libraries by default
which means that you need a copy of libgcc_s_dw2-1.dll and
libstdc++-6.dll files to run your programs build with the GCC4 version
(These files can be found in MinGW\bin directory). To remove these DLL
dependencies, statically link the libraries to your application by
adding "-static-libgcc -static-libstdc++" to your "Extra linking
options" in the project settings.
Try this,
g++ -static-libgcc -static-libstdc++ -Wall -pedantic Hello.cpp -o Hello.exe
I'm afraid to say that with all of the applications installed on my machine, it's easy to identify which ones were built with MinGW. The telltale sign is a folder filled with libraries.
Check to see if the libraries that you need are distributable, and then simply include them in your .exe directory.
Although you may have other applications installed on user's machine, and some of them may contain the libraries that you need, there's a good chance that your application wont be compatible with them. This is why asking your users to install MinGW would be unlikely to work anyways.

SFML2 application cannot find shared objects

I downloaded and compiled SFML2 from git ( debug, release, static and dynamic ) and I successfully compile some sample code from their tutorial using:
g++ main.cpp -lsfml-graphics -lsfml-window -lsfml-system
The problem occurs when I try to run the binary, it can't find any shared objects (libsfml-graphics.so.2, libsfml-window.so.2 etc)
I checked and they are present in /usr/local/lib.
Am I missing something?
Using Fedora 17 x64 and g++ 4.7.2 if that's relevant
/usr/local/lib is normally not searched by the dynamic linker. Add it to LD_LIBRARY_PATH.
Alternatively, configure the dynamic linker to always search /usr/local/lib and perhaps /usr/local/lib64. This is usually done by adding the paths to the /etc/ld.so.conf file, and running ldconfig.
There is sometimes also a 32/64 bit issue, that is, one tries to run a 32-bit executable and only 64-bit libraries are present, or vice versa. Run file <somtething>.so and file <your-executable> to determine their architecture. In general, 32-bit libraries go to <whatever>/lib and 64-bit ones to <whatever>/lib64, but sometimes they end up in a wrong place.

Netbeans 6.9.1 problem finding library on Ubuntu

I am on a time crunch, and I can't seem to get Netbeans (6.9.1) to find a library
I need to incorporate a memory allocator form libcds, I have coded what I believe to be a correct incorporation of the ~/cds-0.8.0/cds/memory/michael/allocator.h file.
The problem I have is that in my Netbeans project, it can't find the library.
I have #include <cds/memory/michael/allocator.h>
but it says it can't find the file. I placed the cds folder next to my main.cpp file.
I also ran the "build-linux-ia64.sh" script in the build folder as well.
I have the boost library installed through apt-get command sudo apt-get install libboost1.40-all
Lastly I am runing UBUNTU (Latest build, fully up to date).
Here is a picture of my project settings as well.
To anyone else wanting to use this library here is the general guide:
First Make Sure you know if your system is 32 bits or 64, do not assume, since it is a 6 core, 8gb of Memory beast that it is running 64, like i did.
1) In the cds-0.8.0/build/sample, copy the script that best suites your os (I have no suggestions for Mac users, as there is no script), and copy it to the build folder (one level up)
2) Run the Script, it may take a while, if it finishes quick check the log.
3) In netbeans u need to set the following configurations
C++ Compiler:
Include Directories: cds-0.8.0
Additional Options: -msse2 -fno-strict-aliasing
The Linker:
Additional Library Directories: cds-0.8.0/bin/gcc-x86-linux-32
Libraries: cds-0.8.0/bin/.../libcds.so
Additional Options: -msse2 -fno-strict-aliasing -shared -fpic
Good Luck, this library has a lot of promise
Note this library is still giving me trouble, but it compiles with these steps