How to compile and execute 32bit C program on 64bit Windows - gcc

I am using a 64bit Intel based machine and want to compile and run 32bit C code in my command prompt. I have bash installed via (Windows Subsystems for Linux) and am using gcc and have the gcc-multilib installed so I can compile using the -m32 tag. The program compiles fine but comes up with this error when I try to run:
bash: ./32test: cannot execute binary file: Exec format error

WSL only supports 64-bit ELF binaries.
https://github.com/Microsoft/BashOnWindows/issues/390
You can try to build with a native Windows compiler or in Cygwin instead.

Related

GCC/G++-11 on windows

Hey I'm trying to compile a program that requires GCC and g++ 11. I've tried msys2 but it only goes up to GCC 10.04
And some of my libraries are supposed to be built on a mingw like environment. So is there any other way of running that program on a windows machine?
Get the latest MinGW-w64 GCC build from https://winlibs.com/

Windows Fortran 64bit

I am using the latest gfortran from MinGW and it seems I'm not getting my code compiled and run in 64bit. Is there a flag or compiler I should be using to take advantage of my 64bit version of Windows 10?

Compile simple C executable on Mac to run on Windows?

I have a simple C program that uses only basic stdio calls (single-threaded file I/O), which I compile on a Mac under clang.
Will this run under Windows? If not, how do I compile it to run under Windows?
You can use ELLCC, a clang based compiler toolchain, to cross compile Windows and Linux executables on a Mac.

Compile using Cygwin without cygwin dependency

-mno-cygwin compiler parameter doesn't exist.
I tried to use '-static', but then compiler can't find installed -lpng
You need to cross compile it. Run x86_64-w64-mingw32-gcc, included in package mingw64-x86_64-gcc-g++, in cygwin64 to cross compile a native windows 64bit executable. It is similar if you are in cygwin or to compile a 32bit executable.
However, without cygwin compatibility layer, a program using POSIX APIs cannot be compiled. If your program needs POSIX APIs, you have to compile with cygwin dependency.
Reference Executable file generated using GCC under cygwin

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

I'm trying to compile a 32-bit C application on RHEL 7 64-bit using gcc 4.8. I'm getting a compiler error /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory. What do I need to do to get 32 bit apps compiled and linked?
To get RHEL 7 64-bit to compile gcc 4.8 32-bit programs, you'll need to do two things.
Make sure all the 32-bit gcc 4.8 development tools are completely installed:
sudo yum install glibc-devel.i686 libgcc.i686 libstdc++-devel.i686 ncurses-devel.i686
Compile programs using the -m32 flag
gcc pgm.c -m32 -o pgm

Resources