Windws-X64 安装GCC

来源:互联网 发布:hf线切割编程软件 编辑:程序博客网 时间:2024/06/08 05:43


gcc for Windows

Introduction

Most Unix and Linux users know the GNU Compiler Collection (gcc). This software compiler system is being used to build a lot of software, including modern operating systems such as Linux and BSD, which means it is well tested and maintained. Additionally, gcc is available under GPL v3 – the most popular free software license. This gives everyone the right to examine and modify its source code and also download it free of charge.

gcc can provide many benefits to developers targeting the Windows platform. In contrary to Visual Studio and most other compiler tools for Windows, gcc is Open Source Software completely free of charge and supported by a large community. Projects targeting multiple operating systems will also save time by using just one compiler system, and if you already know gcc you don’t have to spend time learning new compilers.

Compiling for 64-bit Windows 下载链接 :http://mingw-w64.sourceforge.net/download.php

There are multiple ports of gcc to Windows, but MinGW (Minimalist GNU for Windows) seems to get the most traction. But currently MinGW can only build 32-bit binaries. In order to be able to target both 32-bit (x86) and 64-bit (x64) Windows versions, we will use a flavour of it called MinGW-w64 (aka. mingw64). In addition to the compiler binaries, the package contains headers (e.g. stdlib.h, strings.h, etc.) and libraries necessary to build applications.

Hello World

It is time to get our hands dirty and compile a C-version of Hello World. We will create one for 32-bit Windows and one for 64-bit Windows. The build platform used is a 32-bit Windows XP, but any version of Windows newer than Windows 2000, including Windows Vista and Windows 7 should give the same results. 64-bit versions of Windows will work as well.

  1. Go to the MinGW-w64 download page. We need two toolchains – one for targeting win32 and another for targeting win64. New packages are frequently uploaded, but we just pick the newest personal  build (I had some bad experiences with the automated builds). Open “Toolchains targetting Win32″ and “Toolchains targetting Win64″, followed by “Personal Builds”. 
  2. Unpack the first package to “c:\mingw32″ and the second to “c:\mingw64″.
  3. Open a text editor (e.g. Notepad), paste in the famous world greeting and save it under “c:\tmp\hello.c”.
    #include <stdio.h>
    int main(){  printf("Hello World!\n");  return 0;}
  4. Open a Command Prompt, cd to “c:\tmp” and compile with the following commands. See the related cross-compilation post for an explanation of the compiler names.
    "c:\mingw32\bin\i686-w64-mingw32-gcc.exe hello.c -ohello-w32.exe"
    "c:\mingw64\bin\x86_64-w64-mingw32-gcc.exe hello.c -ohello-w64.exe"
  5. On 32-bit windows (aka. x86), you can only run “hello-w32.exe”, while you can actually run both on 64-bit Windows (aka. x64) because of an emulation layer called Windows 32-bit On Windows 64-bit. It is however much more efficient to run native binaries, that is, “hello-w64.exe” on 64-bit Windows versions.

Build Environment

When building larger projects, we usually want a Unix-like shell in order to run additional tools like configure, make and automake. On Windows, we can use MSYS (Minimal SYStem) to get a shell and the basic commands often used in build-scripts, like grep and sed. This means we can compile code on Windows that will run on Windows, which seems like the natural way to go.

However, note that with the MinGW-w64 suite, it is possible to compile code on Linux that will run on Windows. This is also known as cross-compilation, and will greatly increase the build speed but also allow to use any native Linux shell, rendering MSYS unnecessary. In another post, we consider how to cross-compile Windows binaries on Linux.

Furthermore, real-world applications depend on common libraries. There is a related article on how to compile and use the OpenSSL library on Windows.

转自:

 http://www.blogcompiler.com/2010/06/13/gcc-for-windows/

0 0
原创粉丝点击