Compile linux binaries on windows

Запуск программ Linux в Windows

Для запуска программы Linux в Windows возможны следующие варианты:

  • Запуск программы «как есть» в подсистеме Windows для Linux (WSL). В WSL программа выполняется непосредственно на оборудовании компьютера, а не на виртуальной машине. WSL также поддерживает прямые вызовы файловой системы между системами Windows и Linux, устраняя необходимость в SSL-транспорте. WSL разработана как среда командной строки и не рекомендуется для приложений, интенсивно использующих графику. Дополнительные сведения см. в документации по подсистеме Windows для Linux.
  • Запуск программы «как есть» на виртуальной машине Linux или в контейнере Docker на локальном компьютере или в Azure. Дополнительные сведения см. в разделах Виртуальные машины и Docker в Azure.
  • Компиляция программы с использованием gcc или clang в средах MinGW или MinGW-w64, которые предоставляют слой преобразования системных вызовов Linux в системные вызовы Windows.
  • Компиляция и запуск программы с использованием gcc или clang в среде Cygwin, которая предоставляет более полную среду Linux в Windows по сравнению с MinGW или MinGW-w64.
  • Ручное портирование кода из Linux и компиляция для Windows с использованием Microsoft C++ (MSVC). Этот подход подразумевает рефакторинг кода, не зависящего от платформы, в отдельные библиотеки, и последующее переписывание специализированного кода, относящегося к Linux, в код для Windows (например, для API-интерфейсов Win32 или DirectX). Предположительно, этот вариант лучше всего подходит для приложений, в которых требуется высокопроизводительная графика.

Источник

Running Linux programs on Windows

To run a Linux program on Windows, you have these options:

  • Run the program as-is on the Windows Subsystem for Linux (WSL). In WSL your program executes directly on the machine hardware, not in a virtual machine. WSL also enables direct filesystem calls between Windows and Linux systems, removing the need for SSL transport. WSL is designed as a command-line environment and is not recommended for graphics-intensive applications. For more information, see Windows Subsystem for Linux Documentation.
  • Run the program as-is in a Linux virtual machine or Docker container, either on your local machine or on Azure. For more information, see Virtual Machines and Docker on Azure.
  • Compile the program using gcc or clang in the MinGW or MinGW-w64 environments, which provide a translation layer from Linux to Windows system calls.
  • Compile and run the program using gcc or clang in the Cygwin environment, which provides a more complete Linux environment on Windows compared to MinGW or MinGW-w64.
  • Manually port your code from Linux and compile for Windows using Microsoft C++ (MSVC). This involves refactoring platform-independent code into separate libraries, and then re-writing the Linux-specific code to use Windows-specific code (for example, Win32 or DirectX APIs). For applications that require high performance graphics, this is probably the best option.
Читайте также:  Run as super user linux

Feedback

Submit and view feedback for

Источник

Preface & Content

You want to have a GCC toolchain to compile C/C++ programs for Linux, while you work on your Windows machine? You already use Cygwin on Windows and have Windows 7 / 8 or Windows 10 and do not want to use a slow Virtual Machine?

  • Then you could either switch to use Windows Subsystem for Linux on Windows 10, which provides a more modern alternative provided by Microsoft. Just search for «Ubuntu» or the name of your favourite Linux distribution in the Microsoft Store and click on install.
  • Or you can follow this tutorial to build a GCC Cross-Compiler in Cygwin if you don’t want to or can’t switch to WSL.
  • Installation of Cygwin and needed tools
  • Building of crosstool-ng
  • Allowing a case sensitive file system
  • Building the target toolchain
  • Creating a tarball
  • Installation of the toolchain
  • Testing the toolchain
  • Files

Cygwin tool installation

Download the cygwin installer setup-x86_64.exe from cygwin.com. The crosstool-ng build will need some utilities to succeed. Install the following packages via the graphical installer or use the command line below.

  • tar
  • wget
  • gcc-core
  • gcc-g++
  • binutils
  • make
  • cmake
  • automake
  • autoconf
  • git
  • patch
  • unzip
  • flex
  • bison
  • gperf
  • help2man
  • libtool
  • gettext
  • libgmp10
  • libgmp-devel
  • libmpfr6
  • libmpfr-devel
  • libmpc3
  • libmpc-devel
  • libncurses-devel
  • libintl-devel
setup-x86_64.exe -a x86_64 -d -q -P "tar,wget,gcc-core,gcc-g++,binutils,make,cmake,automake,autoconf,git,patch,unzip,flex,bison,gperf,help2man,libtool,gettext,libgmp10,libgmp-devel,libmpfr6,libmpfr-devel,libmpc3,libmpc-devel,libncurses-devel,libintl-devel"

Building crosstool-ng

Open a bash prompt — named ‘Cygwin64 Terminal’ in the start menu — and execute the following steps. This should build and install crosstools-ng from source and allows the build of recent gcc versions. A benefit of using crosstool-ng is the support for parallel compilation of the target toolchain. This results in an optimal CPU usage of 100% during compilation.

Allowing a case-sensitive file system

Execute the follwing script with a bash prompt (Cygwin64 Terminal) as Administrator (Right-click the shortcut in the start menu. Then select «Run as Administrator»). This configures the Windows file system to allow case-sensitive filenames. You can read more here.

Reboot your PC after this step!
reg ADD "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Kernel" /v obcaseinsensitive /t REG_DWORD /d 0 /f
Bug

Activating the case-sensitivity may break WSL!

Building the toolchain

Start the configuration with the following code snipped. This will create a new directory named compile-cs on your C-drive and mount this folder as case-sensitive file system under /usr/compile. You will need administrator rights on your PC to create a folder directly on your root of the hard drive. So adjust the source path as desired.

Читайте также:  Готовый кс сервер линукс

The next step is to configure the created toolchain.

Select the following under Path and misc options:

  • Local Tarballs: /usr/compile/src
  • Work Directory: /usr/compile/.build
  • Prefix Directory: /usr/compile/x-tools/$

Select under Operating System:

Activate C++ Support under C compiler:

Select the Target options as desired:

x86_64-unknown-linux-gnu

powerpc64-unknown-linux-gnu

  • Architecture: powerpc
  • Architecture Bitness: 64
  • Compile libssp: Yes
  • Compile libsanitizer: yes

Save the configuration and start the build with the following command:

This will take some time. So be prepared to do something else meanwhile.

Creating a tarball

Execute the following script via bash prompt (Cygwin64 Terminal) to create a final archive. This will contain the complete toolchain including system libraries (libc, libcxx) and linux headers.

Installing the toolchain

Add the folder /usr/local/$/bin to your path environment variable (Replace $ with the toolchain-name).

Testing the toolchain

Download the gcc-test.zip archive and run make main_i686 or make main_x86_64. This will build both test applications below via make (c and c++ version) and analyze the generated files.

The respective .txt file contains the generated signature and import table of each application. The content should be similar to the displayed below. You will need a linux machine to run the generated binary files. This can be accomplished with a virtual machine.

Files

gcc 10.2.0 for cygwin64 3.1.7

  • MEGA (fast): x86_64-unknown-linux-gnu-10.2.0.tar.gzDirect (slow): x86_64-unknown-linux-gnu-10.2.0.tar.gz CRC32: 1E2F522D
    MD5: 9A65DB473B74640846703EEDE0452F2D
    SHA-1: 5116FD2CEC0D22EFCE6E2974BC6A216C60E69258
  • MEGA (fast): i686-unknown-linux-gnu-10.2.0.tar.gzDirect (slow): i686-unknown-linux-gnu-10.2.0.tar.gz CRC32: A47ACD7F
    MD5: D04CE11D701BADC5473257376E9EC78E
    SHA-1: 8E95FF3A74A65F03D7ADD571B59ED2EADCEBC52E
  • MEGA (fast): powerpc64-unknown-linux-gnu-10.2.0.tar.gzDirect (slow): powerpc64-unknown-linux-gnu-10.2.0.tar.gz CRC32: EB17E80A
    MD5: 7EB210193F5D138225C3EFB66D855582
    SHA-1: 7FA2CA109A54FF23452B97861B85371A1F3E4B10

gcc 9.2.0 for cygwin64 3.0.7

  • MEGA (fast): x86_64-unknown-linux-gnu-9.2.0.tar.gzDirect (slow): x86_64-unknown-linux-gnu-9.2.0.tar.gz CRC32: DAFB720E
    MD5: BCB53C0ED67F4BAE62853085DAE9619C
    SHA-1: 748582624CD9F966967DDFE12F0D68EA03D82BD2
  • MEGA (fast): i686-unknown-linux-gnu-9.2.0.tar.gzDirect (slow): i686-unknown-linux-gnu-9.2.0.tar.gz CRC32: 8CBA67BE
    MD5: 53FBE54F911C695758126968BB8CF640
    SHA-1: AC983963036957B420F763FC03CCF670EDCF66EE

gcc 7.2.0 for cygwin64 2.9.0

  • MEGA (fast): x86_64-unknown-linux-gnu-7.2.0.tar.gzDirect (slow): x86_64-unknown-linux-gnu-7.2.0.tar.gz CRC32: 7B60472F
    MD5: 1385EEB518EC8B72DEA63BFB27D6451C
    SHA-1: 6F8BC037B74F904EE36752AEF75239F525A37218
  • MEGA (fast): i686-unknown-linux-gnu-7.2.0.tar.gzDirect (slow): i686-unknown-linux-gnu-7.2.0.tar.gz CRC32: C0AAEF50
    MD5: 0E8539E0C63854A0EB6827F4F3917C78
    SHA-1: 613C3B8E7E6A95887F46F765673DC9641774D36B

(Un-)License

See https://www.gnu.org/ and https://github.com/crosstool-ng/crosstool-ng for the applying licenses regarding the used software.

Regarding the used scripts / code on this page:

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

Читайте также:  Debian linux network manager

THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Источник

How to cross compile from windows g++ cygwin to get linux executable file [duplicate]

I have an updated cygwin-full install ,mingw ,codeblocks on a windows system. i have a c++ program which performs xml generation based on input. I understand to build an executable file for unix we use makefiles. makefiles being typical project files . Hence i used the plugin cbp2make.exe to get the makefile for the cbp project file. and i tried to execute make in cygwin. hoping to get a linux executable file. but this was clearly wrong. a typical test c++ test program test.c would be compiled in cygwin using gcc cross compile options like.

this would give us the linux executable file test or if no name is specified it would give an a.out This is all well and good for a simple c++ program with no included header files. I understand when we are dealing with c++ files with lot of external library files a simple g++ -o ourprojfile.exe ourprojectfile.cpp does not work hence we would need to use make files. Question 1 : Am i wrong in assuming this ?* Question 2: how can we setup cross compile to get a linux executable file directly from codeblocks. Update : the problem at my end seems to be missing dependent cpp files which i assumed i included in the main file. The solution was to include them in the main file or simply write handle like so

g++-linux myprog_linux main.cpp first.cpp second.cpp third.cpp 

The problem now is after i get the Linux executable file. when i try to run it on linux machine i get the error of a

 /usr/local/folder/myfile/my_prog_nix: error while loading shared libraries: libstdc++.so.5: cannot open shared object file: No such file or directory 

Источник

Оцените статью
Adblock
detector