How can I use gcc g++ to compile a windows binary if I am running on a Linux OS? - linux

I am working on a project where I have to compile a program which is to run on Windows 7 computers. I only have a Linux computer, so I borrow a friends computer to compile the program before emailing it to the client. Then the client comes back to me with requested alterations, etc.
Can I compile the program for Windows using gcc/g++ for Linux?

try MingW http://www.mingw.org/. perhaps it solve your problem

Related

is it possible to cross-compile from x86(x64) windows to x86(x64) linux?

I have been wonder about why x86(windows) to arm(linux) cross compile is possible but x86(windows) to x86(linux) cross compile is impossible or difficult only can use cygwin
As below link there is some cross-compiler for windows to arm from personal pc(x86), but there is no cross-compiler x86 to x86.
http://gnutoolchains.com/beaglebone/
why window(x86) to Debian(ARM) is available without cygwin , but window to Debian(x86) is difficult or must use cygwin?
Is this issue caused by POSIX size problem? The library size of Debian in ARM is little bit smaller than x86 ones?
I confuse....
I want to anyone clear to me.
Thank you for reading.
I installed WSL and then Debian as an Windows-App
directly under my Windows10 Home Edition.
Now I can open a Linux command prompt in every directory I want.
Installed g++ with apt-get (changed to root with "sudo su").
Using Mingw64 command prompt from the Git-Bash I can even use the same shell script
to compile console apps as Linux and Windows executables!

How to Build GCC For Windows on Linux?

I have a VM running CentOs Linux on my Windows 10 machine. Yesterday I built the GCC from source, and saw an option where you could build it to cross compile. My question is this: is it possible (and if it is, how is it done), to compile GCC so that it is capable of building Windows executables on Linux (that I can then run on my computer)? I would like to avoid using MinGW if at all possible so that I won't have to use the special libraries.

Compiling Fortran using Ifort for Linux under Windows

I develop and run some Fortran Code under Windows (7, 64 bit) using Visual Studio 2010 and ifort.
The code, mostly compiled to a DLL file, is tested on Windows and is deployed approx. 25% of the time to Windows (Windows 2000 up to Windows 7) and 75% to SUSE Linux. While the Windows solution is completely handled by me, the Linux "branch" is compiled by someone other (it is 100% the same code). The Linux branch is compiled with the g95/NAG compiler.
Due to some decisions out of our control, we will change from NAG to gfortran. After some tests, we found the code compiled with gfortran (and some optimisation like -o2) to take about double the time to finish compared to Windows and ifort (no optimisation, full debug). We had a chance to compile the code under Linux and ifort and got about the speed of Windows + ifort. (NAG compiled code is somewhere in between.)
For obvious reasons, we would like to compile the code with ifort for Windows and Linux, so:
Is it possible to compile for SUSE Linux under Windows with ifort (using cmd or Visual Studio 2010)?
I'll answer for Intel - no, you can't compile for Linux in Windows (except using a VM in which case you are really running Linux, as stated above). A VM is a reasonable approach, but you'll have to buy a separate license for ifort on Linux.
Or, as I assume you have a Linux box you will test on, build there (you can SSH to it from your Windows box.) True, you won't have the Visual Studio IDE, but some of our customers use Eclipse (with the Photran plugin) or Code::Blocks with Intel Fortran.

Cross-platform build under Windows targeting Linux using CMake

I am developing a software in C++ on windows 32-bit (using MSVC++), but since I want to be able to use my software on every platform, I have decided to use CMake as my build generator.
Therefore, I am still just a beginner in CMake. From the CMake tutorials, I understand that in order to cross compile codes, first a toolchain simulating the target platform should be installed on the host platform. Then using the appropriate target-platform C and C++ compilers provided by this toolchain, CMake would be able to generate makefiles etc.
Now, I want to build my code for Linux platform(GNU/Linux) on a Win32 platform. I tried doing the above procedure using CMake combined with Cygwin and using gcc and g++ as compilers. It built fine, created makefiles, and when I issued "make" in Cygwin terminal, the generated makefiles were "made". Now I have got an executable which I was hoping would run on Linux platform. But on Linux I get the error: bash cannot execute binary file.
Using command file executablename, I realized the executable which is made by the above procedure is of type PE32 which is only for Windows.
Now my question is: Is my understanding of cross-platform build procedure using cmake correct?Or should I just use another Linux toolchain under windows to get a Linux ELF executable? What toolchains come to your mind which would give me what I want?
Many thanks
Setareh
You will want to look here: cmake-toolchains(7) if you do cross compiling. However, I would suggest that you install a Linux VM like virtual box on your windows machine and build naively on Linux. It will compile much faster and you will not have to worry about cross compiling. You can mount the windows disk from the linux VM so you can share the same source tree. The linux VM will compile much faster than gcc running under windows.
Your understanding of CMake is correct... it will determine how to create the build system you request (or is default for the platform you are currently on) based on rules in your CMakeLists.txt file. However, this won't necessarily help you compile for linux on a windows machine if you don't have something installed that can target linux.
To compile targeting linux, you will need to use a linux compiler. The link posted by #stjin tells you how to install one on cygwin. Then, to set up your CMake build, do this in the terminal:
CC=gcc-linux CXX=g++-linux cmake . [options]
This will tell CMake to locate the special linux targeted compilers. Hopefuly, after compiling with these compilers you will be able to run on linux.

How can I cross compile my Linux application to get a Windows executable in Linux?

I need to cross compile my QT application in Linux. I compiled my application from the QT SDK in Linux and it is working properly.
How do I create an .exe for the same application in Linux. I have installed Mingw in Linux and qmake, but I dont know how to proceed with cross compiling.
How do I link my QT with a cross compiler like MinGW and Qmake. I am using SuSE Linux. I have also gone through http://Silmore/29 but I am not getting a clear picture of how to proceed futher.
I'm not familiar with SuSE, but Ubuntu has the mingw32 packages which is a windows targetted cross compiler, along with the open source win32api:
(source: liranuna.com)
After a small search, turns out there are RPMs for it here, while it should probably be in your repositories.
Basically, you use your cross-toolchain for the Make process rather than the host toolchain. I assume there is no autotools configure script. If there is you can run configure with --host specified and have it all figured out for you.
So what you'll need to do is set CC, LD, CFLAGs, LDFLAGS (probably also CXX and CXXFLAGS) and modify the Makefile to use the right QT libraries - which will need to be mingw, not your Linux libraries. So you may also need to obtain the MinGW/Windows QT SDK and store it separately so your paths cam be specified properly.
Hope this helps!
You could run the Visual C++ Express Edition 2008 cl.exe through wine to compile your project.

Resources