C++ cross-compiler from Windows to Linux [closed]
Closed. This question is seeking recommendations for books, tools, software libraries, and more. It does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Funny: all that stuff going through the VS IDE is what confuses the heck out of me — there’s so much configuration required to get it to work. It’s so much easier on Linux where you don’t have it!
Usually «a cross-compiler from X to Y» would mean, «a compiler that itself runs on X, but produces binaries that run on Y». So you’re asking for a compiler that runs on Windows and produces Linux binaries. Is that what you want? The usual way to do it is to compile for linux on linux. The usual reason for cross-compiling is that Y is not a viable development environment (e.g. because it’s a mobile phone, set-top box, Roomba, etc), maybe you’d be better off finding a Linux IDE you can live with?
@ H.Josef come-one you can compile code for an avr uControler with a compiler running under windows and you can’t compile code for linux using a compiler that runs under windows . I don’t believe that .
@neo_x3m AFAIK you can compile standard C++ code using any compiler, but creating a library (and testing it) on a completely different operating system is cumbersome and even impossible, Once I tried to create and test a dynamic linux library (.so) using MingW and it did not work, it did not work even with Cygwin since Windows environment is very different from Linux.
Running the Linux binary would be very cumbersome, but if you have all the libs/OBJ in Linux format, but compiling is nothing magical. if a Linux compiler app would run on Windows, why shouldn’t it work? Why couldn’t you even compile a Linux compiler under Windows?
5 Answers 5
- Install cygwin, with development packages
- Download crosstool-ng
- Extract the tarball ( tar xvjf crosstool-ng* )
- Run ./configure
- When configure complains about a missing tool, go back to cygwin setup and install the corresponding package (e.g. flex , libtool , ncurses-devel ) You’ll need at least the following:
- Devel/gperf
- Devel/bison
- Devel/byacc
- Devel/wget
- Devel/patch
- Devel/make (GNU version)
- Devel/automake 1.10+
- Libs/libncursesw10
- Libs/libncursesw10-devel
- the _libintl_gettext error as mentioned in the comments
- the byteshift headers, and
- the ELF headers (Thanks Duncan Calvert & osm0sis)
Of course, this is NOT going to enable you to build linux applications from inside Visual Studio. (VS2010 and later let you build with other toolchains such as gcc, but you’d need an appropriate toolchain description in addition to the cross-compiler built by crosstool-ng). But you’ll have a working g++-linux-gnu , which you can either run directly or using a Makefile.
NOTE: Building the cross-compiler takes a LONG time. osm0sis has provided a prebuilt gcc 4.8.1 here, along with his notes on building the cross-compiler (used to update this answer).
Manual for cross-compiling a C++ application from Linux to Windows?
Is there a manual for cross-compiling a C++ application from Linux to Windows? Just that. I would like some information (links, reference, examples. ) to guide me to do that. I don’t even know if it’s possible. My objective is to compile a program in Linux and get a .exe file that I can run under Windows.
3 Answers 3
The basics are not too difficult:
sudo apt-get install mingw32 cat > main.c EOF i586-mingw32msvc-cc main.c -o hello.exe
Replace apt-get with yum , or whatever your Linux distro uses. That will generate a hello.exe for Windows.
Once you get your head around that, you could use autotools, and set CC=i586-mingw32msvc-cc
CC=i586-mingw32msvc-cc ./configure && make
Or use CMake and a toolchain file to manage the build. More difficult still is adding native cross libraries. Usually they are stored in /usr/cross/i586-mingw32msvc/ and you would need to add those paths in separately in the configure step of the build process.
One thing to note with this is that some libraries don’t like to cross-compile. If your only choices are an .exe installer and source, you may want to install the library under wine and then copy the libraries and headers into your mingw search path. I never could get Boost to cross-compile
WINE is okay for stupid-simple programs like this, but a VM (VirtualBox, VMWare, QEMU, etc) is your best bet.
If you want to generate a 64-bit Windows binary, install the 64-bit tools: $ sudo apt-get install mingw-w64 . The compiler is x86_64-w64-mingw32-gcc .
It depends on what you mean (I couldn’t really say).
- If you mean that you want to use an existing Linux application on Windows, then you could try compiling it using Cygwin on Windows. This however does not give you a Windows executable free from all dependencies towards Cygwin (your executable still depends on the cygwin.dll file) — and it still may need some porting before it will work. See http://www.cygwin.com.
- If you mean that you want to be able to perform the actual compilation of a Windows application on Linux and produce a .exe file that is executable on Windows — thus using your Linux box for development and/or compilation then you should look into MinGW for Linux which is a tool for crosscompiling for Windows on Linux. See http://www.mingw.org/wiki/LinuxCrossMinGW.
I suggest you give the following, GUB (Grand Unified Builder) a try as it cross-compiles several packages with their dependencies and assembles them into a single installation package for currently 11 architectures. You can download a prebuilt iso for installation in a VM from here and follow the source here. It can currently be used to cross-compile GNU LilyPond/ GNU Denemo / Inkscape and OpenOffice.org.
The target architectures are:
- darwin-ppc — tar.bz2 file for Darwin 7 (MacOS 10.3)/PowerPC
- darwin-x86 — tar.bz2 file for Darwin 8 (MacOS 10.4)/x86
- mingw — mingw executable for Windows32
- linux-x86 — shar archive for Linux/x86
- linux-64 — shar archive for Linux/x86_64
- linux-ppc — shar archive for Linux/PowerPC
- freebsd-x86 — shar archive for FreeBSD 4/x86
- freebsd-64 — shar archive for FreeBSD 6/x86_64
- cygwin — .tar.bz2 packages for Cygwin/Windows32
- arm — shar archive for Linux/ARM (largely untested)
- debian — shar archive for Debian (largely untested)
Linked
Related
Hot Network Questions
Subscribe to RSS
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.7.14.43533
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.