您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
008第三章 顺序程序设计02-命令行下编译与运行
发布时间:2021-04-09 21:22:49编辑:雪饮阅读()
在前面咱们一直是在vc6++上面进行程序代码的编写、编译与运行。
其实这个vc6++感觉体验也不是很好的。
这里来介绍另外一种c语言程序的编写、编译与运行。
哪里该方法的核心就是gcc
那一般呢我们是在这个网站http://www.mingw-w64.org/doku.php/download
下载MingW-W64的windows安装包然后一键安装即可,但是这个安装包不是离线的。
需要连接网络下载一些资源。
选择标准:
32位系统选择i686, 64位系统选择x86_64
线程模型:win32 : 没有C ++ 11多线程特性, posix : 支持C ++ 11多线程特性
异常处理模型:32位系统推荐dwarf,64位系统推荐seh
当你选择了相关参数后会出现一个下载进度条对应有一个资源文件是7z后缀的,假如我这里的就是x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z
那么我们就下载x86_64-8.1.0-release-posix-seh-rt_v6-rev0并解压,解压后找到其bin目录,例如我这里解压后放在d盘后bin目录如:D:\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\mingw64\bin
我们把这个目录放到path环境变量中。
然后我们新开一个cmd控制台如果能运行gcc命令就算成功了。
C:\Users\Administrator>gcc
gcc: fatal error: no input files
compilation terminated.
C:\Users\Administrator>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=D:/x86_64-8.1.0-release-posix-seh-rt_v6-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/8.1.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-8.1.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64 --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw810/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=https://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/include -I/c/mingw810/prerequisites/x86_64-zlib-static/include -I/c/mingw810/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw810/x86_64-810-posix-seh-rt_v6-rev0/mingw64/opt/lib -L/c/mingw810/prerequisites/x86_64-zlib-static/lib -L/c/mingw810/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
那么接下来随便找个路径建立一个.c的c程序如:
#include <stdio.h>
void main(){
printf("%c\n",'h');
}
然后我们这个程序路径是d:\hello.c
那么我们gcc进行编译如:
C:\Users\Administrator>gcc d:\hello.c
那么我们运行如:
C:\Users\Administrator>a.exe
H
这里我们编译之后所生成的.exe可运行程序是位于当前编译命令gcc所运行在的目录,而不是编译目标.c文件所在的目录,并且默认生成的可运行exe文件名为“a”。
那么其实我们也可以自定义编译输出目录及文件名,用-o参数来指定如:
C:\Users\Administrator>gcc d:\hello.c -o d:\xy
C:\Users\Administrator>d:\xy.exe
h
关键字词:c,c语言,顺序程序,命令行
上一篇:008第三章 顺序程序设计02
下一篇:009第三章 顺序程序设计03