Linux 64 bit build

Linux environment to build 32 and 64-bit application (C++)

I’m looking for advice on how to set up a build machine for a Linux application that needs to be compiled for both 32 and 64-bit architectures. As far as I know, I’ll need a 64 bit OS, which can build both 32 and 64. Adding the -m32 flag will produce the right output for 32, no challenge here. The main issue is with libraries. I’m not sure on how to proceed. How can I make sure the linker is using the 32 bit versions of simple libraries, such as ldl, lz, lrt? I understand I must install the 32 bit versions of all of them, and then configure the linker path. Another issue is the version of the compiler, linker, libc and so on. Should I use the oldest versions, in order to ensure all clients will run without issues? I mean, if I build the app in the latest Debian, in older Debians it won’t work properly, correct? Thanks for the help!

It might be easier to just have virtual machines of the different architectures, and then there will be no confusion. Alternatively, I think you could also have a 32-bit chroot inside your 64-bit Linux, and build your 32-bit version from inside the chroot. I’m not sure though.

1 Answer 1

Most versions of Linux that have a 64-bit build also make a 32-bit build and nearly all libraries are available for both, so all you need to do is install the relevant 32-bit libraries in parallel with the 64-bit ones. The configuration of paths is no different than for a pure 64- or 32-bit build in most cases. There may be a few libraries that have problems, but you really need to go looking for those. All of the mainstream packets will have libraries that work with 32- and 64-bit library versions both installed at the same time.

Читайте также:  Установить имя компьютера linux

When it comes to «which libc», etc, that’s a more difficult question, since it will really depend on what your customers have on their machines — and it’s unlikely that you can dictate that they should be using one of Debian, RedHat or SuSE — they will feel very strongly about using whatever they are using. Using a «too old» library is just as bad as using a «too new» library. The usual solution to this is to build multiple versions, one for a selected RedHat release (and that should work with a few steps newer/older version, typically, as well as the Fedora versions in the same range), a Debian version, and a SuSE version, maybe one or two more distros.

And yes, at that point, you probably want to set up a build machine with a few virtual machines on it, so that you don’t have to have 3, 5, or 12 physical machines.

Источник

How to Compile 32-bit Apps on 64-bit Ubuntu?

I’m trying to compile a 32-bit C application on Ubuntu Server 12.04 LTS 64-bit using gcc 4.8. I’m getting linker error messages about incompatible libraries and skipping -lgcc . What do I need to do to get 32 bit apps compiled and linked?

3 Answers 3

This is known to work on Ubuntu 16.04 through 22.04:

sudo apt install gcc-multilib g++-multilib 

Then a minimal hello world:

compiles without warning with:

gcc -m32 -ggdb3 -O0 -pedantic-errors -std=c89 \ -Wall -Wextra -pedantic -o main.out main.c 
main.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=87c87a83878ce7e7d23b6236e4286bf1daf59033, not stripped 

but fails on an x86_64 executable with:

./main.out: Invalid ELF image for this architecture 

It is a shame that this package conflicts with the cross compilers like gcc-arm-linux-gnueabihf https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1300211

Читайте также:  Установка linux ubuntu server

Running versions of the question:

We are able to run 32-bit programs directly on 64-bit Ubuntu because the Ubuntu kernel is configured with:

grep CONFIG_IA32_EMULATION "/boot/config-$(uname -r)" 
Include code to run legacy 32-bit programs under a 64-bit kernel. You should likely turn this on, unless you're 100% sure that you don't have any 32-bit programs left. 

This is in turn possible because x86 64 bit CPUs have a mode to run 32-bit programs that the Linux kernel uses.

TODO: what options does gcc-multilib get compiled differently than gcc ?

Doesn’t work in podman/docker container with Ubuntu 18.04. As a matter of fact, I don’t see why would it ever work, because the mentioned gcc-multilib packages barely has any files, and certainly it has no libraries in them.

So, what helped for me in a docker/podman container with Ubuntu, is to install lib32gcc-10-dev (worth noting, the 10 version in my case is from PPA; without PPA it would be a lower version).

To get Ubuntu Server 12.04 LTS 64-bit to compile gcc 4.8 32-bit programs, you’ll need to do two things.

  1. Make sure all the 32-bit gcc 4.8 development tools are completely installed: sudo apt-get install lib32gcc-4.8-dev
  2. Compile programs using the -m32 flag gcc pgm.c -m32 -o pgm

Note that the -m32 flag is specific to 32-bit x86. You need different flags to compile for 32-bit ARM, RISC-V, etc.

Multiarch installation is supported by adding the architecture information to the package names you want to install (instead of installing these packages using alternative names, which might or might not be available).

See this answer for more information on (modern) multiarch installations.

In your case you’d be better off installing the 32bit gcc and libc:

sudo apt-get install libc6-dev:i386 gcc:i386 

It will install the 32-bit libc development and gcc packages, and all depending packages (all 32bit versions), next to your 64-bit installation without breaking it.

Читайте также:  Поиск крупных файлов linux

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

minimal x86_64 Linux based os

License

arjuncr/minimal_x86_64_os

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

use build_x86_64.sh for building os (x86_64)

Update existing repo to latest.

apt install build-essential apt install bison flex libelf-dev xorriso apt install qemu qemu-system apt-get install libssl-dev 

Buiding os from source: (./build_x86_64.sh)

################################################################################################### ###################################Utility-1.5 to Build x86_64 OS################################## ################################################################################################### Help message --help Build and create iso: --build-img Build All: --build-all Rebuild All: --rebuild-all Clean All: --clean-all Wipe and rebuild --wipe-rebuild Building kernel: --build-kernel --rebuild-kernel --clean-kernel Building busybx: --build-busybox --rebuild-busybox --clean-busybox Building other soft: --build-other --rebuild-other --clean-other Creating root-fs: --create-rootfs Create ISO Image: --create-img Cleaning work dir: --clean-work-dir Test with Qemu --Run-qemu ###################################################################################################### 

./build_x86_64.sh —build-img 4 64

./build_x86_64.sh —build-img 4 32

Источник

Оцените статью
Adblock
detector