My whole stack of the road -C basis of language integrated development environment to build
2.1 C language integrated development environment to build
The current mainstream operating systems (Windows, Linux, macOS) has improved the C language integrated development environment for editing, compiling, debugging, deployment package C program.
operating system | development tools |
---|---|
Windows10 1903 | Visual Studio2019 |
macOS10.14 | XCode10.3 |
Ubuntu18.04 | QT5.13 |
Windows as the world's most popular desktop operating system, the most current version Windows10 1903, VisualStudio on Windows as the most powerful integrated development environment, can develop Windows software, games, Web applications, and so on, the latest version VisualStudio2019 16.2.2.
Ubuntu is one of the most popular desktop Linux system, recommended QT cross-platform integrated development environment to write C / C ++ program.
MacOS platform is recommended to use XCode to write C / C ++ program, and XCode on macOS system is built-in, no additional installation.
In addition to some cross-platform C / C ++ development tools, such CLion from Jetbrains company can also be used to write C / C ++ program.
On installing and using the IDE, their official website provides detailed tutorials, students can go on their own inspection.
C language learning process will use Windows10 1903 + Visual Studio 2019 development environment as the main, if not otherwise specified, the default environment is Windows10 1903 and Visual Studio 2019.
2.2 Visual Studio Code C language to achieve HelloWorld
HelloWorld is to learn a programming language entry procedures, if you can write independently and run HelloWorld, then it means that entered the programming of the door.
Visual Studio Code is Microsoft's open-source, cross-platform (Windows, Ubuntu, macOS) editor here use it to write source code in C language.
为什么首先要使用Visual Studio Code来编写第一个C程序呢,因为Visual Studio Code只是一个编辑器,用于编写源码,并不提供编译或者解释运行程序的功能。通过它来对比之前介绍的IDE,体验下使用IDE开发程序带来的好处,也有利于理解IDE背后的机制。
- 在D盘的code目录下创建源文件helloworld.c,C语言的源文件都是以.c结尾的。
编辑源文件
#include <stdio.h>
int main(int argc, char* argv[]) {
printf("Hello World Windows10 1903 & Visual Studio Code & C ");
return 0;
}
- 编译源文件
将源文件编译成对应平台的可执行程序,因为计算机不能识别开发人员编写的源文件内容,只能识别二进制的机器指令。而C语言编写的源程序可以使用多种编译器来编译:Windows系统可以安装QT或者Visual Studio 2019后编译源文件
QT中自带了GCC编译器,以QT5.13为例,将QT的默认安装路径(C:\Qt\Qt5.13.0\Tools\mingw730_64\bin) 添加到系统的PATH环境目录下
然后在Windows命令行的终端中输入gcc -v,看到类似如下输出,就可以使用gcc编译器了
C:\Users\ittim>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=C:/Qt/Qt5.13.0/Tools/mingw730_64/bin/../libexec/gcc/x86_64-w64-mingw32/7.3.0/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-7.3.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw730/x86_64-730-posix-seh-rt_v5-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 --enable-libstdcxx-filesystem-ts=yes --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/mingw730/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw730/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw730/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/mingw730/x86_64-730-posix-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -fno-ident -I/c/mingw730/x86_64-730-posix-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS=' -I/c/mingw730/x86_64-730-posix-seh-rt_v5-rev0/mingw64/opt/include -I/c/mingw730/prerequisites/x86_64-zlib-static/include -I/c/mingw730/prerequisites/x86_64-w64-mingw32-static/include' LDFLAGS='-pipe -fno-ident -L/c/mingw730/x86_64-730-posix-seh-rt_v5-rev0/mingw64/opt/lib -L/c/mingw730/prerequisites/x86_64-zlib-static/lib -L/c/mingw730/prerequisites/x86_64-w64-mingw32-static/lib '
Thread model: posix
gcc version 7.3.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)
gcc编译源文件并运行生成的可执行文件
D:\code>dir
驱动器 D 中的卷是 DATA
卷的序列号是 B0FB-1B0A
D:\code 的目录
2019/08/18 10:48 <DIR> .
2019/08/18 10:48 <DIR> ..
2019/08/18 10:46 159 helloworld.c
1 个文件 159 字节
2 个目录 205,122,088,960 可用字节
D:\code>gcc helloworld.c -o helloworld.exe
D:\code>helloworld.exe
Hello World Windows10 1903 & Visual Studio Code & C
Visual Stuido 2019只需要在路径C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2019\Visual Studio Tools下运行 Developer Command Prompt for VS2019后 使用cl命令编译源文件命令即可。
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.2.2
** Copyright (c) 2019 Microsoft Corporation
**********************************************************************
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise>d:
D:\>cd code
D:\code>cl helloworld.c
用于 x86 的 Microsoft (R) C/C++ 优化编译器 19.22.27905 版
版权所有(C) Microsoft Corporation。保留所有权利。
helloworld.c
Microsoft (R) Incremental Linker Version 14.22.27905.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:helloworld.exe
helloworld.obj
D:\code>helloworld.exe
Hello World macOS & Visual Studio Code & C
2.3 Visual Studio 2019集成GitHub
在正式使用Visual Studio 2019开发C语言的程序时,可以集成GitHub插件,编译后期代码统一管理。
Github is an open source project hosting platform, you must first create an account before using it. Follow all the source files will be uploaded to GitHub C program, so even if the replacement computer, just from the remote to the local GitHub project to clone.
- Start Visual Studio 2019
- Download Visual Studio plug-in GitHub
click Visual Studio menu extension -> Management Extensions
Then click online, choose GitHub Extension for Visual Studio click download.
- GitHub plug-in installed
later in Visual Studio 2019 plug-in is downloaded GitHub need to manually close the Visual Studio 2019, and then will automatically begin the installation process
At this point Visual Studio will go to GitHub networking download plug-ins, if you encounter download super slow network reasons, can scan two-dimensional code download below
Then close VisualStudio2019, enter C: \ Program Files (x86) \ under Microsoft Visual Studio \ 2019 \ Enterprise \ Common7 \ IDE directory enter cmd
At this point it has entered the C: \ Program Files (x86) \ 2019 \ Common7 \ IDE directory under Microsoft Visual Studio \ Enterprise \, just type VSIXInstaller.exe C: \ Users \ ittim \ Desktop \ GitHub.VisualStudio.vsix and back after the car can begin to install the plug GitHub
- Connection GitHub
GitHub plug-in installation is complete, restart Visual Studio 2019
First, the project switched from Solution Explorer to Team Explorer, and click Connect GitHub
-
Login GitHub
user name and password to log on GitHub
-
Creating a warehouse
first click Create menu
Then set the warehouse name, description and local repository path, Git ignore, License
If all goes well, can be accessed using a browser to access the address https://github.com/ittimeline/c-core-programming project, simply replace the students want to ittimeline into your account.