环境:win10
安装和测试gcc
install
-
download: http://sourceforge.net/projects/mingw/files/latest/download?source=files
-
click to install at
C:\minGW\
-
添加路径到环境变量: 右键我的电脑→属性→高级系统设置→环境变量→系统变量
将
C:\minGW\bin
添加到path
中 -
继续安装
gcc-c++
,gcc-make
:打开C:\minGW\bin
,双击.exe
文件,在打开的图形界面中勾选需要安装的项
test
打开命令行,键入gcc -v
和make -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
网友评论