2024年最新Linux(CentOS 7)使用gcc编译c,c++代码_centos7下编译alist,2024年最新5年经验C C++程序员面试27天

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以添加戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

}


### 二 通过gcc --help查看gcc命令参数


* 看不懂可以直接看下一节常用编译命令选项,会有详细讲解



Usage: gcc [options] file…
Options:
-pass-exit-codes Exit with highest error code from a phase
–help Display this information
–target-help Display target specific command line options
–help={common|optimizers|params|target|warnings|[^]{joined|separate|undocumented}}[,…]
Display specific types of command line options
(Use ‘-v --help’ to display command line options of sub-processes)
–version Display compiler version information
-dumpspecs Display all of the built in spec strings
-dumpversion Display the version of the compiler
-dumpmachine Display the compiler’s target processor
-print-search-dirs Display the directories in the compiler’s search path
-print-libgcc-file-name Display the name of the compiler’s companion library
-print-file-name= Display the full path to library
-print-prog-name= Display the full path to compiler component
-print-multiarch Display the target’s normalized GNU triplet, used as
a component in the library path
-print-multi-directory Display the root directory for versions of libgcc
-print-multi-lib Display the mapping between command line options and
multiple library search directories
-print-multi-os-directory Display the relative path to OS libraries
-print-sysroot Display the target libraries directory
-print-sysroot-headers-suffix Display the sysroot suffix used to find headers
-Wa, Pass comma-separated on to the assembler
-Wp, Pass comma-separated on to the preprocessor
-Wl, Pass comma-separated on to the linker
-Xassembler Pass on to the assembler
-Xpreprocessor Pass on to the preprocessor
-Xlinker Pass on to the linker
-save-temps Do not delete intermediate files
-save-temps= Do not delete intermediate files
-no-canonical-prefixes Do not canonicalize paths when building relative
prefixes to other gcc components
-pipe Use pipes rather than intermediate files
-time Time the execution of each subprocess
-specs= Override built-in specs with the contents of
-std= Assume that the input sources are for
–sysroot= Use as the root directory for headers
and libraries
-B Add to the compiler’s search paths
-v Display the programs invoked by the compiler
-### Like -v but options quoted and commands not executed
-E Preprocess only; do not compile, assemble or link
-S Compile only; do not assemble or link
-c Compile and assemble, but do not link
-o Place the output into
-pie Create a position independent executable
-shared Create a shared library
-x Specify the language of the following input files
Permissible languages include: c c++ assembler none
‘none’ means revert to the default behavior of
guessing the language based on the file’s extension

Options starting with -g, -f, -m, -O, -W, or --param are automatically
passed on to the various sub-processes invoked by gcc. In order to pass
other options on to these processes the -W options must be used.


### 三 常用编译命令选项


假设源程序文件名为test.c


1. 无选项编译链接  
 用法:`#gcc test.c`  
 作用:将test.c预处理、汇编、编译并链接形成可执行文件。这里未指定输出文件,默认输出为a.out。编译成功后可以看到生成了一个a.out的文件。在命令行输入./a.out 执行程序。./表示在当前目录,a.out为可执行程序文件名。
2. 选项 -o  
 用法:`#gcc test.c -o test`  
 作用:将test.c预处理、汇编、编译并链接形成可执行文件test。-o选项用来指定输出文件的文件名。输入./test执行程序。
3. 选项 -E  
 用法:`#gcc -E test.c -o test.i`  
 作用:将test.c预处理输出test.i文件。
4. 选项 -S  
 用法:`#gcc -S test.i`  
 作用:将预处理输出文件test.i汇编成test.s文件。
5. 选项 -c  
 用法:`#gcc -c test.s`  
 作用:将汇编输出文件test.s编译输出test.o文件。
6. 无选项链接  
 用法:`#gcc test.o -o test`  
 作用:将编译输出文件test.o链接成最终可执行文件test。输入./test执行程序。


如果想直接输入test就运行,需要把test复制到目录/usr/bin下


7. 选项-O  
 用法:`#gcc -O1 test.c -o test`  
 作用:使用编译优化级别1编译程序。级别为1~3,级别越大优化效果越好,但编译时间越长。输入./test执行程序。


8.编译使用C++ std库的程序  
 用法:`#gcc test.cpp -o test -l std c++` 作用:将test.cpp编译链接成test可执行文件。-l std c++指定链接std c++库。


### 四 多源文件的编译方法




![img](https://img-blog.csdnimg.cn/img_convert/623907b19544135a7925ed4bf5bcc552.png)
![img](https://img-blog.csdnimg.cn/img_convert/a35bad5fd68b70ec9fe8eb77eb9fb052.png)

**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!**

**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618668825)**

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**

**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618668825)**

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值