这里写目录标题
一级目录
GNU C Compiler 的缩写,经过十来年发展,意义变成了 GNU Compiler Collection,可同时支持 C、C++、Objective C和Java 等.
1.编译第一个C/C++程序
只编译执行一个C程序
$ gcc hello.c
$ ./a.out
$Hello world!
-
默认的a.out 并不友好,gcc 提供 -o 选项指定执行文件的文件名:
$gcc -o hello hello.c ##编译源代码,并把可执行文件命名为 hello
$Hello world! -
编译C++程序,我们可以直接用GCC 编译其中的g ++命令,用法同 gcc;当然g++ 和 gcc 都可以用来编译 c 和 c++程序。gcc 编译c++程序需要带上 -lstdc++ 指定使用c++库。
注:安装g++时如果很慢,建议:
使用vim 编辑 /etc/apt/sources.list 文件,在文件的尾部换行加入如下内容:
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
接下来执行: apt-get update 命令,再调用 sudo apt-get install g++
修改程序的名字:
程序跑起来:
正在下载g++,从国外网下载
编译常用选项
注意:-c 选项在编写大型程序是必须的,多个文件的源代码首先需要编译成目标代码,再链接成执行文件。如果由多个源文件,工程做法建议采用 makefile 。
编译生成的汇编代码
预处理的结果
.
.
.
在Windows让编程效率飞起来
- Ubuntu安装Samba 服务器
确认安装: dpkg -l | grep samba
安装: sudo apt-get install samba samba-common
卸载: sudo apt-get autoremove samba
查询安装包
- Samba服务器配置
sudo vi /etc/samba/smb.conf
在文件最后添加
[Share]
comment=This is samba dir
path=/home/martin/
writable=yes
browseable=yes
增加samba 用户
#sudo smbpasswd -a martin
可以通过局域网使Linux系统和window系统连接到一起,而后可以在window系统界面系统上进行操作文件!!!
- 启动和关闭
启动Samba服务器: sudo service smbd start
关闭Samba服务器: sudo service smbd stop
-
直接在Windows 下编码
-
编辑器的选择
编辑器的作用:
编写程序(源代码)。
编辑器的选择:
初学者最好使用最简单的文本编辑器,不要使用集成开发环境IDE
Linux平台:vi, vim, 或gedit
Windows平台:记事本,Sublime Text, UltraEdit, notePad, notePad++, source insight