|
发表于 2021-9-2 20:46:52
|
显示全部楼层
本楼为最佳答案
就是编译选项吧?
一般来说,下面这个就够了
- 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.
复制代码
|
|