win10下gcc的安裝和make

環(huán)境:win10

安裝和測(cè)試gcc

install

  1. download: http://sourceforge.net/projects/mingw/files/latest/download?source=files

  2. click to install at C:\minGW\

  3. 添加路徑到環(huán)境變量: 右鍵我的電腦→屬性→高級(jí)系統(tǒng)設(shè)置→環(huán)境變量→系統(tǒng)變量

    C:\minGW\bin添加到path

  4. 繼續(xù)安裝gcc-c++,gcc-make:打開C:\minGW\bin,雙擊.exe文件,在打開的圖形界面中勾選需要安裝的項(xiàng)

1530005994918.png

test

打開命令行,鍵入gcc -vmake -v以查看是否安裝

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>gcc -v   
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community>make -v
GNU Make 3.82.90
Built for i686-pc-mingw32
Copyright (C) 1988-2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

gcc測(cè)試

新建test.c文件:

#include<stdio.h>  
#include<stdlib.h>  
int main(void){  
 printf("Hello, world!\n");
 system("pause");
 return 0;
}

在命令行中cd到當(dāng)前path,進(jìn)行編譯:gcc text.c -o test.exe即可運(yùn)行test.exe

make測(cè)試

新建文件夾,在文件夾中新建max.c:

#include "max.h"  
int max(int a, int b)  
{  
 return a > b ? a : b;
}

max.h:

int max(int a, int b); 

max_num.c:

#include <stdio.h>  
#include <stdlib.h>  
#include "max.h"  

int main(void)  
{  
 printf("The bigger one of 3 and 5 is %d\n", max(3, 5));
 system("pause");
 return 0;
} 

makefile:

max_num.exe: max_num.o max.o  
 gcc -o max_num.exe max_num.o max.o

max_num.o: max_num.c max.h  
 gcc -c max_num.c

max.o: max.c max.h  
 gcc -c max.c
  • gcc前是tab而不是space

cd到當(dāng)前文件夾后make

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容