I know that if I want to compile a 32 bit .exe for windows on Linux I can just install and use the mingw32 package (e.g. apt-get install mingw32) on linux. What if I want to compile a windows .exe that is 64 bit? Is there tools or a method to do this?
It looks like my answer lies with the Mingw-w64 project which is available for host OSes Linux, Darwin & Windows
I know this question is very old and already has an accepted answer but I will post this answer the way I do it now. It is pretty simple and straightforward and I hope it helps anyone landing here:
To cross-compile windows applications from a Linux machine you just need to install mingw-w64 C and C++ compiler. On debian based system you just do this:
sudo apt install -y gcc-mingw-w64 g++-mingw-w64
That will install the gcc (the c compiler) and g++ (the c++ compiler) for both 64 and 32 bit cross-compilation
After that, if you need a 64-bit application just do:
x86_64-w64-mingw32-g++ hello.c -o hello.exe
And if you need a 32-bit application just do:
i686-w64-mingw32-g++ hello.c -o hello.exe
Simple as that!
It's also possible to install MinGW from MSYS2. The main advantages are:
Usually up-to-date MinGW, regardless of what your Linux distribution ships.
A lot of prebuilt libraries.
Several MinGW flavors are provided: x32 and x64, with different C runtimes, etc.
You can't install MSYS2 on Linux directly, but it's possible with Quasi-MSYS2.
Install Clang (and LLD):
On Ubuntu:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh
rm llvm.sh
Clang can cross-compile to Windows using MSYS2 libraries. Alternatively, you can run MSYS2 MinGW in Wine, but it's slower.
Install dependencies:
sudo apt install make wget tar zstd gpg wine
Wine is optional.
Install Quasi-MSYS2 and any desired MSYS2 packages:
git clone https://github.com/HolyBlackCat/quasi-msys2
cd quasi-msys2/
# Optionally, choose MSYS2 flavor, see full list at: https://www.msys2.org/docs/environments/
# echo MINGW64 >msystem.txt
make install _gcc _gdb
Then:
env/shell.sh opens a shell with the correct environment variables set up.
win-clang++ hello.cpp invokes Clang with flags for cross-compilation.
./a.exe runs the resulting app in Wine, if it's installed.
Full disclosure: I'm the developer of quasi-msys2.
Related
When typing pacman -S gcc, it will install gcc in /usr/bin in msys2, but when typeing pacman -S mingw-w64-x86_64-gcc, it will install in /mingww64/bin.
What is different between them?
The GCC compiler in /usr/bin produces executables that use msys-2.0.dll as a runtime dependency. That DLL is basically a fork of Cygwin, and it provides emulation of POSIX commands not normally available on Windows. That environment is mainly for running programs from the Linux world (like bash) which need POSIX commands and cannot be easily ported to a native Windows environment.
The GCC compilers in /mingw32/bin and /mingw64/bin produce native Windows executables targeting the 32-bit or 64-bit versions of Windows respectively. The 32-bit executables can actually run on 32-bit or 64-bit Windows. These executables are easier to distribute; you generally just copy all the DLLs that they depend on from the /mingw*/bin folder to the same directory as your executable, and then you have something that will run successfully on other computers. Since the main purpose of MSYS2 is to help write native Windows software, you'll find a much wider variety of libraries in the MinGW environments than in the msys-2.0.dll environment.
I have set up target fs on
/home/myself/filesys/bin..etc//
GCC
compile:
host $ arm_v5t_le-gcc hello.c -o hello
run:
target $ cd /opt/hello
target $./hello
I have installed opencv2.3 on host ubuntu machine now I want opencv to be ported to DM6446
so i follow
uncompress opencv2.3 tarball
sudo cmake OpenCV-2.3.1
sudo make ARCH=arm CROSS_COMPILE=arm_v5t_le-
but when I run the sample test from bin it runs on x86 machine which was made for ARM
I think I am not following the correct procedure to make opencv.
Is there anything I have to do to make opencv for ARM architecture,
what are the steps to follow in cross compiling?
The 2nd command you executed should provide a clue as to whether you are cross-compiling or not. If you look closely it would have shown that it was building for the i686 and not for the ARM platform.
This blog discusses how to Cross Compile using cmake.
cmake uses different environment variables from standard make (so don't use ARCH, and CROSS-COMPILE).
I wrote simple GTKmm program from here and try to cross-compile it for windows using mingw cross-compiler, but it fails. My output is here.
When I compile simple program using just GTK gtk.h header it works perfectly - compiles (using the same command) and run on Windows.
I am running Fedora LXDE spin and using GTKmm-2.4 (from win).
Everything else works fine - I can comile for UNIX GTK and GTKmm but for Win just GTK. I have my PKG_CONFIG_LIBDIR set properly (one for UNIX and one for Win)
Thanks for any advice - I also tried to install new libsigc++ from Yum Extender but nothing.
Fedora includes a number of MinGW cross compiled libraries, including gtkmm 2.4 and libsigc++. I see you are using gtkmm installed in /home/michal/Dropbox/GTK/GTKmm-Devel/; have you tried using the system packages?
To install the binary packages: 'yum install mingw32-gtkmm24'
... and then to compile the hello world sample, run:
i686-pc-mingw32-g++ helloworld.cc main.cc -o helloworld.exe `i686-pc-mingw32-pkg-config gtkmm-2.4 --cflags --libs`
Also, the Fedora MinGW project has a mailing list and an IRC channel where people can help get you started.
I am using gcc/g++ to compile c/c++ applications - living on OpenSuSe btw.
Is there any way (some option i guess) so that g++ will produce an executable suitable for windows ?
You can search for a mingw32 package in OpenSuSE (I know there is one for Debian) or install it manually. Then if you have a configure script the command line would be something like this in order to have make use the MinGW cross-compilation toolchain:
./configure --prefix=/usr/local --target=i386-mingw32
mingw.org also has a tutorial on building a cross compiler, don't know if that works.
(As an aside: Some websites point to mirzam.it.vu.nl/mingw containing MinGW RPM packages but it seems like that site is down.)
You'll have to be running g++ on Windows to get a Windows executable out of the other end.
Check out mingw or cygwin.
Check out MinGW Cross and related links:
http://www.nongnu.org/mingw-cross-env/#see-also
Please let me know if this should be on Server Fault...
I've got some code I want to compile which requires arm-elf-gcc. I'm not an embedded programmer, so all this is new to me. My development machine is a Mac and I use fink pretty often, so I'd love to be able to install it that way. However, fink doesn't know of any package with that name. I see that gnuarm.org has some binaries for OS X but their packages seem to also include a bunch of stuff (e.g. gcc) I already have. Am I correct in believing that I need to install binutils, newlib and a file called t-arm-elf?
MacPorts supports arm-elf-gcc.
$ port search arm-elf
arm-elf-binutils #2.20.51.0.2 (cross, devel)
FSF Binutils for arm-elf cross development
arm-elf-gcc #4.3.2 (cross, devel)
gcc cross-compilers for arm-elf, with newlib runtime library.
arm-elf-gcc3 #3.4.6 (cross, devel)
gcc 3.x cross-compilers for arm-elf, with newlib runtime library.
Found 3 ports.
Once you install MacPorts, all it would take is:
$ sudo port install arm-elf-gcc