Hi,
I've c source code developed in 32-bit linux machine. Can I run it in 64-bit linux machine.
Thank you.
Santos
Hi,
I've c source code developed in 32-bit linux machine. Can I run it in 64-bit linux machine.
Thank you.
Santos
Short practical answer: if the machines share the same CPU family (e.g., 32-bit x86 -> 64-bit x86_64) you can usually run 32-bit programs on the 64-bit host, provided the kernel has 32-bit support and the required 32-bit user libraries are present. If the CPU families differ (ARM, PowerPC, etc.) you will need to rebuild for the target or use emulation/virtualization. This expands on points from , and by giving concrete checks and steps.
Quick checks you can run immediately:
file ./your_binary
ldd ./your_binary If file shows "ELF 32-bit" and ldd lists missing 32-bit libraries, install the 32-bit runtime for your distribution. On Debian/Ubuntu (multiarch):
sudo dpkg --add-architecture i386
sudo apt update
sudo apt install libc6:i386 libstdc++6:i386 To build 32-bit binaries on a 64-bit dev host install the multilib toolchain and use -m32:
sudo apt install gcc-multilib g++-multilib
gcc -m32 -o prog prog.c On RPM-based systems install the .i686 runtime packages (glibc.i686, libstdc++.i686) or use equivalent package names for your distro. If the binary is statically linked it may run without extra libs; if dynamically linked you need the matching 32-bit shared objects.
Porting caveats: code that assumes sizeof(long)==4 or casts pointers to int will break when moved to 64-bit. Replace such assumptions with fixed-width and pointer-sized types (int32_t, intptr_t, uintptr_t, size_t) and use the correct printf macros (e.g., PRIuPTR) to avoid silent bugs. If the program contains inline assembly, raw syscall numbers, or architecture-specific optimizations, rebuild and audit those sections or run under a container/VM/emulator (chroot/debootstrap, Docker, QEMU) instead.
References and further reading: Debian Multiarch documentation (for the dpkg/apt approach), GCC code-generation options (for -m32), and C integer/type refs for portability (Debian Multiarch, GCC Code-Gen Options, C integer types).
Jump to Post— Grunt 19That depends on the code.
Jump to Post— Salem 6,009Providing the author did the job properly, all you need to do is recompile it on the target machine.
That depends on the code.
Providing the author did the job properly, all you need to do is recompile it on the target machine.
unlike MS-Windows, not all *nix machines were created equally. A 32-bit program compiled on one *nix computer may or may not run on another 32-bit *nix computer, unless the hardware is identical. There are many different flavors of linux/unix computers and they run many different chip sets (or whatever they are called) (80x88, risk, etc). Programs have to be recompiled for each of these different machine types.
Yes, generally you must recompile code for different archs/non-standard kernels in Linux.
[offtopic]Mac OS X Leopard has a special backwards-compatibility regarding 64 and 32 bit apps[/offtopic]
In some distributions you can, if you're on the AMD64, i.e. x86-64 architecture, since it's a superset of x86 -- there are issues that come up, like the fact that you need thirty-two-bit libraries /and/ sixty-four-bit libraries installed on the system.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.