鱼C论坛

 找回密码
 立即注册
查看: 3980|回复: 26

[已解决]求论坛中(外)的 GCC/G++ 相关的优秀的教程帖子

[复制链接]
发表于 2021-9-2 11:47:04 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 奶茶newfish 于 2021-9-2 11:48 编辑

记得之前在论坛的那个板块下看到过 GCC/G++ 相关的帖子,但是忘记收藏了。
现在想求一篇好的文章。同时也记录一下。

有奖回答,1/2 的概率中奖
最佳答案
2021-9-2 20:46:52
奶茶newfish 发表于 2021-9-2 20:37
是的是的,我看了一下官网,没找到 API

就是编译选项吧?
一般来说,下面这个就够了
gcc -g -Wall -o main main.c
       gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-Wpedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] [@file] infile...

       Only the most useful options are listed here; see below for the
       remainder.  g++ accepts mostly the same options as gcc.
       -g  Produce debugging information in the operating system's native
           format (stabs, COFF, XCOFF, or DWARF).  GDB can work with this
           debugging information.

           On most systems that use stabs format, -g enables use of extra
           debugging information that only GDB can use; this extra information
           makes debugging work better in GDB but probably makes other
           debuggers crash or refuse to read the program.  If you want to
           control for certain whether to generate the extra information, use
           -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below).


           -Wall turns on the following warning flags:

           -Waddress -Warray-bounds=1 (only with -O2) -Warray-parameter=2 (C
           and Objective-C only) -Wbool-compare -Wbool-operation
           -Wc++11-compat  -Wc++14-compat -Wcatch-value (C++ and Objective-C++
           only) -Wchar-subscripts -Wcomment -Wduplicate-decl-specifier (C and
           Objective-C only) -Wenum-compare (in C/ObjC; this is on by default
           in C++) -Wformat -Wformat-overflow -Wformat-truncation
           -Wint-in-bool-context -Wimplicit (C and Objective-C only)
           -Wimplicit-int (C and Objective-C only)
           -Wimplicit-function-declaration (C and Objective-C only)
           -Winit-self (only for C++) -Wlogical-not-parentheses -Wmain (only
           for C/ObjC and unless -ffreestanding) -Wmaybe-uninitialized
           -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation
           (only for C/C++) -Wmissing-attributes -Wmissing-braces (only for
           C/ObjC) -Wmultistatement-macros -Wnarrowing (only for C++)
           -Wnonnull -Wnonnull-compare -Wopenmp-simd -Wparentheses
           -Wpessimizing-move (only for C++) -Wpointer-sign
           -Wrange-loop-construct (only for C++) -Wreorder -Wrestrict
           -Wreturn-type -Wsequence-point -Wsign-compare (only in C++)
           -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess
           -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch
           -Wtautological-compare -Wtrigraphs -Wuninitialized
           -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value
           -Wunused-variable -Wvla-parameter (C and Objective-C only)
           -Wvolatile-register-var -Wzero-length-bounds

           Note that some warning flags are not implied by -Wall.  Some of
           them warn about constructions that users generally do not consider
           questionable, but which occasionally you might wish to check for;
           others warn about constructions that are necessary or hard to avoid
           in some cases, and there is no simple way to modify the code to
           suppress the warning. Some of them are enabled by -Wextra but many
           of them must be enabled individually.

       -o file
           Place the primary output in file file.  This applies to whatever
           sort of output is being produced, whether it be an executable file,
           an object file, an assembler file or preprocessed C code.

           If -o is not specified, the default is to put an executable file in
           a.out, the object file for source.suffix in source.o, its assembler
           file in source.s, a precompiled header file in source.suffix.gch,
           and all preprocessed C source on standard output.

           Though -o names only the primary output, it also affects the naming
           of auxiliary and dump outputs.  See the examples below.  Unless
           overridden, both auxiliary outputs and dump outputs are placed in
           the same directory as the primary output.  In auxiliary outputs,
           the suffix of the input file is replaced with that of the auxiliary
           output file type; in dump outputs, the suffix of the dump file is
           appended to the input file suffix.  In compilation commands, the
           base name of both auxiliary and dump outputs is that of the primary
           output file type; in dump outputs, the suffix of the dump file is
           appended to the input file suffix.  In compilation commands, the
           base name of both auxiliary and dump outputs is that of the primary
           output; in compile and link commands, the primary output name,
           minus the executable suffix, is combined with the input file name.
           If both share the same base name, disregarding the suffix, the
           result of the combination is that base name, otherwise, they are
           concatenated, separated by a dash.

                   gcc -c foo.c ...

           will use foo.o as the primary output, and place aux outputs and
           dumps next to it, e.g., aux file foo.dwo for -gsplit-dwarf, and
           dump file foo.c.???r.final for -fdump-rtl-final.

           If a non-linker output file is explicitly specified, aux and dump
           files by default take the same base name:

                   gcc -c foo.c -o dir/foobar.o ...

           will name aux outputs dir/foobar.* and dump outputs dir/foobar.c.*.

           A linker output will instead prefix aux and dump outputs:

                   gcc foo.c bar.c -o dir/foobar ...

           will generally name aux outputs dir/foobar-foo.* and
           dir/foobar-bar.*, and dump outputs dir/foobar-foo.c.* and
           dir/foobar-bar.c.*.

           The one exception to the above is when the executable shares the
           base name with the single input:

                   gcc foo.c -o dir/foo ...

           in which case aux outputs are named dir/foo.* and dump outputs
           named dir/foo.c.*.

           The location and the names of auxiliary and dump outputs can be
           adjusted by the options -dumpbase, -dumpbase-ext, -dumpdir,
           -save-temps=cwd, and -save-temps=obj.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-2 11:55:03 | 显示全部楼层

回帖奖励 +2 鱼币

你指的是 GCC/G++ 的使用教程?
man 手册加百度完全够用
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-2 12:01:34 | 显示全部楼层
哦,再加 Google 翻译
Google 翻译对程序员比较友好,有道翻译相对来说要差一点
也许说成是差很多?居然翻译出一个完全相反的结果,^_^
3.png
2.png
1.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-2 20:37:28 | 显示全部楼层
人造人 发表于 2021-9-2 11:55
你指的是 GCC/G++ 的使用教程?
man 手册加百度完全够用

是的是的,我看了一下官网,没找到 API
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-2 20:46:52 | 显示全部楼层    本楼为最佳答案   
奶茶newfish 发表于 2021-9-2 20:37
是的是的,我看了一下官网,没找到 API

就是编译选项吧?
一般来说,下面这个就够了
gcc -g -Wall -o main main.c
       gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-Wpedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] [@file] infile...

       Only the most useful options are listed here; see below for the
       remainder.  g++ accepts mostly the same options as gcc.
       -g  Produce debugging information in the operating system's native
           format (stabs, COFF, XCOFF, or DWARF).  GDB can work with this
           debugging information.

           On most systems that use stabs format, -g enables use of extra
           debugging information that only GDB can use; this extra information
           makes debugging work better in GDB but probably makes other
           debuggers crash or refuse to read the program.  If you want to
           control for certain whether to generate the extra information, use
           -gstabs+, -gstabs, -gxcoff+, -gxcoff, or -gvms (see below).


           -Wall turns on the following warning flags:

           -Waddress -Warray-bounds=1 (only with -O2) -Warray-parameter=2 (C
           and Objective-C only) -Wbool-compare -Wbool-operation
           -Wc++11-compat  -Wc++14-compat -Wcatch-value (C++ and Objective-C++
           only) -Wchar-subscripts -Wcomment -Wduplicate-decl-specifier (C and
           Objective-C only) -Wenum-compare (in C/ObjC; this is on by default
           in C++) -Wformat -Wformat-overflow -Wformat-truncation
           -Wint-in-bool-context -Wimplicit (C and Objective-C only)
           -Wimplicit-int (C and Objective-C only)
           -Wimplicit-function-declaration (C and Objective-C only)
           -Winit-self (only for C++) -Wlogical-not-parentheses -Wmain (only
           for C/ObjC and unless -ffreestanding) -Wmaybe-uninitialized
           -Wmemset-elt-size -Wmemset-transposed-args -Wmisleading-indentation
           (only for C/C++) -Wmissing-attributes -Wmissing-braces (only for
           C/ObjC) -Wmultistatement-macros -Wnarrowing (only for C++)
           -Wnonnull -Wnonnull-compare -Wopenmp-simd -Wparentheses
           -Wpessimizing-move (only for C++) -Wpointer-sign
           -Wrange-loop-construct (only for C++) -Wreorder -Wrestrict
           -Wreturn-type -Wsequence-point -Wsign-compare (only in C++)
           -Wsizeof-array-div -Wsizeof-pointer-div -Wsizeof-pointer-memaccess
           -Wstrict-aliasing -Wstrict-overflow=1 -Wswitch
           -Wtautological-compare -Wtrigraphs -Wuninitialized
           -Wunknown-pragmas -Wunused-function -Wunused-label -Wunused-value
           -Wunused-variable -Wvla-parameter (C and Objective-C only)
           -Wvolatile-register-var -Wzero-length-bounds

           Note that some warning flags are not implied by -Wall.  Some of
           them warn about constructions that users generally do not consider
           questionable, but which occasionally you might wish to check for;
           others warn about constructions that are necessary or hard to avoid
           in some cases, and there is no simple way to modify the code to
           suppress the warning. Some of them are enabled by -Wextra but many
           of them must be enabled individually.

       -o file
           Place the primary output in file file.  This applies to whatever
           sort of output is being produced, whether it be an executable file,
           an object file, an assembler file or preprocessed C code.

           If -o is not specified, the default is to put an executable file in
           a.out, the object file for source.suffix in source.o, its assembler
           file in source.s, a precompiled header file in source.suffix.gch,
           and all preprocessed C source on standard output.

           Though -o names only the primary output, it also affects the naming
           of auxiliary and dump outputs.  See the examples below.  Unless
           overridden, both auxiliary outputs and dump outputs are placed in
           the same directory as the primary output.  In auxiliary outputs,
           the suffix of the input file is replaced with that of the auxiliary
           output file type; in dump outputs, the suffix of the dump file is
           appended to the input file suffix.  In compilation commands, the
           base name of both auxiliary and dump outputs is that of the primary
           output file type; in dump outputs, the suffix of the dump file is
           appended to the input file suffix.  In compilation commands, the
           base name of both auxiliary and dump outputs is that of the primary
           output; in compile and link commands, the primary output name,
           minus the executable suffix, is combined with the input file name.
           If both share the same base name, disregarding the suffix, the
           result of the combination is that base name, otherwise, they are
           concatenated, separated by a dash.

                   gcc -c foo.c ...

           will use foo.o as the primary output, and place aux outputs and
           dumps next to it, e.g., aux file foo.dwo for -gsplit-dwarf, and
           dump file foo.c.???r.final for -fdump-rtl-final.

           If a non-linker output file is explicitly specified, aux and dump
           files by default take the same base name:

                   gcc -c foo.c -o dir/foobar.o ...

           will name aux outputs dir/foobar.* and dump outputs dir/foobar.c.*.

           A linker output will instead prefix aux and dump outputs:

                   gcc foo.c bar.c -o dir/foobar ...

           will generally name aux outputs dir/foobar-foo.* and
           dir/foobar-bar.*, and dump outputs dir/foobar-foo.c.* and
           dir/foobar-bar.c.*.

           The one exception to the above is when the executable shares the
           base name with the single input:

                   gcc foo.c -o dir/foo ...

           in which case aux outputs are named dir/foo.* and dump outputs
           named dir/foo.c.*.

           The location and the names of auxiliary and dump outputs can be
           adjusted by the options -dumpbase, -dumpbase-ext, -dumpdir,
           -save-temps=cwd, and -save-temps=obj.
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-2 20:47:23 | 显示全部楼层
奶茶newfish 发表于 2021-9-2 20:37
是的是的,我看了一下官网,没找到 API
man gcc
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-2 21:12:17 | 显示全部楼层
c语言中文
博客园
C语言论坛
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2021-9-3 09:23:35 | 显示全部楼层

好的好的,谢谢啦
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-3 16:13:29 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-3 17:49:39 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-3 17:51:13 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-3 17:52:48 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-4 13:09:01 | 显示全部楼层

回帖奖励 +2 鱼币

学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-5 16:00:36 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-10 12:30:07 | 显示全部楼层

回帖奖励 +2 鱼币

学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-10 14:42:16 | 显示全部楼层
学习学习
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2021-9-10 18:51:11 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-15 21:33:10 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-16 13:03:58 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-9-17 09:36:54 | 显示全部楼层

回帖奖励 +2 鱼币

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-18 17:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表