美文网首页实验室日常
win10下gcc的安装和make

win10下gcc的安装和make

作者: Lutein | 来源:发表于2018-06-26 17:53 被阅读26次

    环境:win10

    安装和测试gcc

    install

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

    2. click to install at C:\minGW\

    3. 添加路径到环境变量: 右键我的电脑→属性→高级系统设置→环境变量→系统变量

      C:\minGW\bin添加到path

    4. 继续安装gcc-c++,gcc-make:打开C:\minGW\bin,双击.exe文件,在打开的图形界面中勾选需要安装的项

    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测试

    新建test.c文件:

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

    在命令行中cd到当前path,进行编译:gcc text.c -o test.exe即可运行test.exe

    make测试

    新建文件夹,在文件夹中新建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到当前文件夹后make

    相关文章

      网友评论

        本文标题:win10下gcc的安装和make

        本文链接:https://www.haomeiwen.com/subject/yrvmyftx.html