How can I link glibc statically with qt - linux

I have built a static version of qt and download a static version of glibc. Now I would like to link glibc statically to my qt application. I know about going into the .pro and adding the line LIBS += -L path/to/static_lib but I am wondering if these that is enough? Will it still link glibc statically even though the OS I am building on has the dynamic libraries also? The reason I am doing this is to deploy the application in a standalone manner. (After installing and updating Red Hat 5.3 glibc_2.9 was not found on the target computer)

Passing -static to gcc will force it to link statically when possible.
Alternatively, download and install CentOS 5 and build on that.

As you discovered, linking fully statically with glibc is not possible, because for instance nss support is loaded dynamically.
However, the required glibc version depends mostly on the features you actually use.
Anyway, I think you should instead use Linux Standard Base, also
because of reasons exposed here.

Related

Resources for how to retarget mingw like you can retarget GCC?

I know you can retarget GCC (with difficulty), but I'm not sure if the same thing is possible with mingw. I've found some excellent resources for how to retarget gcc itself, but I can't figure out if they apply to mingw's version, since none of GCC's folder structure appears to be present in my install of mingw. Is it even possible? If so, can someone provide resources for me to get started?

Applications reporting “libc.so.6: cannot handle TLS data” after upgrading glibc

Background Info:
Linux OS: Stripped down, minimalistic and very customized (no apt-get, yum, etc)
Linux Kernel: 2.6.19.1
Current glibc version: 2.3.6
Target glibc version: 2.6.1
Issue:
Attempting to install an ipk package provided by 3rd party which has a dependency on a glibc version >= 2.6 (current version is 2.3.6)
The 3rd party provided a different ipk package to upgrade glibc to 2.6.1. After executing the install of the package, all other applications that depend upon glibc report "libc.so.6: cannot handle TLS data"
Is anyone familiar with upgrading glibc on a customized Linux OS without using any sort of package manager for support?
My understanding is that glibc should be backwards compatible and upgrading it shouldn't cause issues with applications that had previously been working. Is this assumption incorrect?
I can post more information as it is requested. Any and all help is greatly appreciated, thank you in advance.
My understanding is that glibc should be backwards compatible and upgrading it shouldn't cause issues with applications that had previously been working.
That is correct.
Your issue is most likely the result of mismatch between ld-linux and libc.so.6 -- they must come from the same build, of bad things will happen (GLIBC actually consists of many libraries, and they all must match).
It's possible that your 3rd-party provided glibc package is mis-configured and replaced one, but not the other. Possibly it installed libc.so.6 into /usr/local/lib instead of whatever location is appropriate for your OS.
So find all files that "belong" to GLIBC before the installation of 3rd-party update, and verify that every one of them is replaced by it.
It is also possible, though less likely, that the 3rd party package is simply broken, or configured without TLS support.
If you link an app against GLIBC with TLS support, then upgrade GLIBC to one configured without TLS support, the applications will break. That is expected and "normal" (configuring GLIBC without TLS support is simply not a good idea).

GCC - Dynamic Dependencies

Good day! I've got a problem with linkage on Linux using gcc. For example, I've compiled project on one machine and linked it with libGLEW. When I'm trying to run it on another machine - it can't find libGLEW, because first machine has libGLEW.so.1.7 and second has libGLEW.so.1.10.
ldd shows me, that it dependent on 'libGLEW.so.1.7'.
after creating symlink 'libGLEW.so.1.7 => libGLEW.so.1.10' everything works fine, but is there a way, to store 'libGLEW.so' as dependency instead of 'libGLEW.so.1.7'?
What makes you sure the function interface of GLEW doesn't have changed?
Or even the content of version 1.1 to 1.7 is still the same?
If it is build with 1.7, it also depends on 1.7.
So you shouldn't run it on another version of GLEW, except the api documentation of GLEW tells you that this cross versioning is possible for some reason (But I couldn't imagine that).
Otherwise also build it with GLEW 1.1 in addition
(because as if all features you use from 1.7 are also supported by 1.1 and for some reason you have to support both versions), so to serve different versions fo your programm for different versions of GLEW would be the best and valid way.
If that is not the case make it for the user as requirement to be on Glew version 1.7 or higher.
But there is no safe way of working around to archive what you want.
And there is not a gcc or any compiler command for that at all.

Run-everywhere statically-linked gcc binary for Linux

I have an old SuSE-10.1 setup which works basically fine, but has a broken YaST (package manager) and no gcc. (Yes, I am in progress of moving one website after another to another server to get rid of that fossil, so please don't tell me to "upgrade", but it's a slow process and I have to maintain it.)
To install anything from source, I need a C-compiler - preferrably one that doesn't need any shared libraries and runs on 32-bit.
Where can I get (or how can I create) such a binary?
You can retrieve a precompiled version with static-get
static-get -x gcc

Setting up a cross-compilation environment for a specific target platform

I'd like to set up a cross-compilation environment on a Ubuntu 9.10 box. From the documents I've read so far (these ones, for example) this involves compiling the toolchain of the target platforms.
My question is: how do you determine the required version of each of the packages in the toolchain for a specific target platform? Is there any rule of thumb I can follow?
This is a list found in one of the websites linked above:
binutils-2.16.1.tar.bz2
linux-2.6.20.1.tar.bz2
glibc-2.5.tar.bz2
glibc-linuxthreads-2.5.tar.bz2
gcc-core-4.2.0.tar.bz2
gcc-g++-4.2.0.tar.bz2
But suppose I want to generate executables for standard Ubuntu 8.04 and CentOS 5.3 boxes. What are the necessary packages?
My primary need is to avoid errors like "/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.11' not found" in the customers' machines but in the future I want to deal with different architectures as well.
It is generally a good idea to build a cross-toolchain that uses the same version of libc (and other libraries) found on the target system. This is especially important in the case of libraries that use versioned symbols or you could wind up with errors like "/usr/lib/libstdc++.so.6: version 'GLIBCXX_3.4.11' not found".
Same Architecture
For generating executables for standard Ubuntu 8.04 and CentOS 5.3 systems, you could install the distributions in virtual machines and do the necessary compilation from within the virtual machine to guarantee the resulting binaries are compatible with the library versions from each distribution.
Another option would be to setup chroot build environments instead of virtual machines for the target distributions.
You could also build toolchains targeted at different environments (different library versions) and build under your Ubuntu 9.10 environment without using virtual machines or chroot environments. I have used Dan Kegel's crosstool for creating such cross-toolchains.
Different Architecture
As I noted in my answer to a another cross-compiler question, I used Dan Kegel's crosstool for creating my arm cross-toolchain.
It appears it may be slightly out of date, but there is a matrix of build results for various architectures to help determine a suitable combination of gcc, glibc, binutils, and linux kernel headers.
Required Package Versions
In my experience, there really isn't a rule of thumb. Not all combinations of gcc, binutils, glibc, and linux headers will build successfully. Even if the build completes, some level of testing is necessary to validate the build's success. This is sometimes done by compiling the Linux kernel with your new cross-toolchain. Depending on the target system and architecture, some patching of the source may be necessary to produce a successful build.
Since you are setting up this cross-compilation environment on Ubuntu 9.10, you might want to look into the dpkg-cross package.
Compiling for other Linux distributions is easiest by installing them in virtual machines (apt-get install kvm) and then doing the compilation from within. You can also script them to do it automatically. Building a cross-compiler and providing the exact same versions of all libraries and such, as the other Linux distro does, is nearly impossible.
My question is: how do you determine
the required version of each of the
packages in the toolchain for a
specific target platform?
...
binutils-2.16.1.tar.bz2
gcc-core-4.2.0.tar.bz2
gcc-g++-4.2.0.tar.bz2
Generally pick the latest stable: these only affect your local toolchain, not runtime.
linux-2.6.20.1.tar.bz2
You don't need this. (For targeting embedded platforms you might use it.)
glibc-2.5.tar.bz2
glibc-linuxthreads-2.5.tar.bz2
You don't need these. I.e. you should not download them or build them; you should link against the versions from the oldest distro you want to support.
Is there any
rule of thumb I can follow?
But suppose I want to generate
executables for standard Ubuntu 8.04
and CentOS 5.3 boxes. What are the
necessary packages?
You survey the distros you want to target, find the lowest common denominator versions of
of libc, libstdc++, pthreads, and any other shared library you will link with, then copy these libs and corresponding headers from the box that has these LCD versions to your toolchain.
[edit] I should clarify, you really want to get all the dependent libs from a single system. Picking and choosing the LCD of each file version from different distributions is a recipe for a quick trip to dependency hell.
Depending on your target platforms, have you considered using Optware?
I'm currently working on getting Mono and Moonlight built for my Palm Pre using the cross-compilation toolchain (and the Optware makefiles handle the majority of dependencies already).

Resources