Re: [问题] g++

楼主: ric2k1 (Ric)   2013-10-06 22:26:31
如果你的程式只有一个 .cpp 档,
先 compile 成 .o 档再 compile 程执行档是没有差的 (well, 后者多一步啦!)
但如果你有多个 .cpp 档,直接用 -o 再接所有 .cpp 档的话,
每次都会把所有的 .cpp 档都重新 compile 一次,
这样对于大型程式在做 incremental fixing/enhancement 的时候是会很浪费时间的。
所以,对于多重 .cpp 档你最好先把每个 .cpp 档 compile 成 .o 档
(g++ -c; 并且检查 dependency, 以减少重新 compile 的档案数目),
然后再 link 成执行档。
至于 -g -Wall 要放 g++ 的哪里,答案是随便,
请看一下 g++ 的 usage (man g++):
====
NAME
gcc - GNU project C and C++ compiler
SYNOPSIS
gcc [-c|-S|-E] [-std=standard]
[-g] [-pg] [-Olevel]
[-Wwarn...] [-pedantic]
[-Idir...] [-Ldir...]
[-Dmacro[=defn]...] [-Umacro]
[-foption...] [-mmachine-option...]
[-o outfile] infile...
Only the most useful options are listed here; see below for the remain-
der. g++ accepts mostly the same options as gcc.
====
By convention, 方括号 "[ ]" 内的参数为 optional (可有可无),
optional arguments 之间的顺序可以任意调换。
当然,"[-o outfile]" 表示 -o 后面的字串会被视为是 output file,
所以不可以在 -o 后面随便插入其他参数,否则会被当作档名。
但对于 compile & linking 来说,
"-g -Wall" 应该是要放在 -c (compile) 的时候来生成 debug information,
linking 时可以不用放。
※ 引述《ColaNut (可乐果)》之铭言:
: 标题: [问题] g++
: 时间: Sun Oct 6 10:57:17 2013
:
: (举手)
:
: g++ -c a.cpp
: g++ -o out a.o
:
: v.s.
:
: g++ -o out a.cpp
:
:
作者: ColaNut   0000-00-00 00:00:00
呜呜,写写老师打这么多~

Links booklink

Contact Us: admin [ a t ] ucptt.com