Compile simple C executable on Mac to run on Windows? - 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.

Related

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

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.

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

compiling static library for windows in cygwin

I'm trying to compile a library (dxflib) for use in windows using cygwin.
I'm loosely following the instructions found here: http://www.ribbonsoft.com/doc/dxflib/2.5/reference/dxflib-reference-manual.pdf
I can get it to compile to make a .a library (ie a unix static library), using 'make' but obviously I'm using cygwin because I want to compile a .lib for use in windows.
When I try to use 'MinGW32-make' (or any other derivative I can think of) cygwin claims that it doesn't exist. I've reinstalled all options with mingw or gcc or g++ remotely in their name in cygwin.
Does anybody know how to get it to compile from the makefile to produce a .lib? Thanks.

powerpc compiler on windows gives "c++ compiler not installed on this system error"

I am trying to use msys powerpc-eabispe-gcc compiler on windows to compile a simple helloworld.cpp program, inorder to generate an elf for powerpc architecture, but I am getting "c++ compiler not installed on this system" error. The bin folder of powerpc-eabispe contains all the exe's, I dont understand why then I get this error??
I used MinGW command prompt to run this command: powerpc-eabispe-gcc.exe -o hello hello.cpp
You need to install the toolchain for the architecture you are targeting.
Search for "cctools" / "binutils" / "crosstools" or "ppc cross-compile environment".
You can also take a look at:
Building and Testing gcc/glibc cross toolchains (This will probably work)
Host/Target specific installation notes for GCC (search powerpc in the page)
However, I would encourage you to try this on a linux or on a mac computer. There are far more resources & docs available on the web for cross-compilation on these platforms.

Compile problems with native raspberry pi

The problem
We are trying to compile the spi_slave code on a raspberry pi. We used the native gcc compiler and the compile runs without any errors.
The problem is when I try to run the output:
/home/pi/spi_slave# ./build/output.elf
Segmentation fault
/home/pi/spi_slave# ./build/kernel.img
bash: ./build/kernel.img: cannot execute binary file
Tried to download the arm-none-eabi compiler from cambridge but it wont run:
/home/pi/spi_slave# ../arm-2008q3/bin/arm-none-eabi-gcc
bash: ../arm-2008q3/bin/arm-none-eabi-gcc: cannot execute binary file
Sourcecode
The code we are trying to compile is: http://tylernichols.me/wp-content/uploads/2012/11/raspberry_pi_bare_metal_spi_slave.zip
The only change we did was in the makefile, added a # in front of the ARMGNU var
#ARMGNU = arm-none-eabi
Environement
# uname -a
Linux raspberrypi 3.6.11+ #371 PREEMPT Thu Feb 7 16:31:35 GMT 2013 armv6l GNU/Linux
What am I doing wrong?
We have tried to find answers on google and stackoverflow for hours now without success. :/
arm-none-eabi is a non-linux compiler. It is for bare-metal applications. The difference is in the C library. However, gcc is intimately linked to the C library for normal compiles.
Then there is the code. It is not written for Linux. It is written for a bare-metal application. You need to load and run the code from the Raspberry-Pi boot loader (berryboot?) without Linux.
You can use the ARM Linux compiler to create code for a bare-metal application. However, it is probably easier for you to find a newlib compiler that is targeted for the Raspberry Pi. You can search for one on the web or try to build one yourself.
See: How to build gcc for Raspberry Pi and Bare-metal gcc.

Resources