编译“发行版本” [英] Compiling for "Release Version"

查看:122
本文介绍了编译“发行版本”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我正在编写自己的代码,编译它并测试它,因为我去了b $ b,我通常编译如下:


gcc * .c -ansi -pedantic -Wall -o executable


如果我正在使用第三方库,我通常会这样做以下内容:


gcc * .c -Wall -o可执行文件



gcc * .c -o executable


如果我的代码经过了充分测试并且我确定它完美无缺,我将按照以下方式编译



gcc * .c -O3 -D NDEBUG -s -o可执行文件


我能理解为什么我们不使用-D NDEBUG或-s当测试

,因为我们想要捕获断言的断言,但我很好奇

是否有任何理由回避使用 -O3" (或者对于任何编译器的任何

优化)在调试版本中?


When I''m writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

gcc *.c -ansi -pedantic -Wall -o executable

If I''m using 3rd-party libraries, I''ll usually do the following:

gcc *.c -Wall -o executable

When I''ve already tested my code and I''m distributing it to other
people to use, I tend to tell them to compile as follows:

gcc *.c -o executable

If my code has been well-tested and I''m certain it works perfectly, I
compile as follows:

gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don''t use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I''m curious as to
whether there''s any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?

推荐答案

Tomásóhéilidhe写道:
Tomás ó héilidhe wrote:

当我正在编写自己的代码,编译它并测试它时,我会按照以下方式编译:b $ b $


gcc * .c -ansi -pedantic -Wall -o executable


如果我正在使用第三方库,我'通常会执行以下操作:


gcc * .c -Wall -o executable


当我已经测试了我的代码时我正在将它分发给其他人使用,我倾向于告诉他们编译如下:


gcc * .c -o executable


如果我的代码经过了充分测试并且我确定它完美无缺,那么我将根据以下内容进行编译:


gcc * .c -O3 -D NDEBUG -s -o可执行


我能理解为什么我们不使用-D NDEBUG"或-s当测试

,因为我们想要捕获断言的断言,但我很好奇

是否有任何理由回避使用 -O3" (或者对于任何编译器的任何

优化)在调试版本中?
When I''m writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

gcc *.c -ansi -pedantic -Wall -o executable

If I''m using 3rd-party libraries, I''ll usually do the following:

gcc *.c -Wall -o executable

When I''ve already tested my code and I''m distributing it to other
people to use, I tend to tell them to compile as follows:

gcc *.c -o executable

If my code has been well-tested and I''m certain it works perfectly, I
compile as follows:

gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don''t use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I''m curious as to
whether there''s any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?



因为优化的代码很难调试。根据编译器

和调试器,你不会在你认为应该的地方结束,你不能检查它们可能已被优化掉的变量,您可能无法看到

函数的参数等。由于优化的形式通常是

默认值,对于调试版本,我倾向于明确地将其关闭,例如。

with -O0。

另外-g(对于可执行文件中的符号)或编译器使用的任何内容

,通常不是默认设置的一部分,所以我会在调试版本上打开

。对于gcc even -g3。


再见,Jojo

Because optimized code can be very hard to debug. Depending on the compiler
and debugger you don''t end up where you think you should, you can''t inspect
variables as they might have been optimized away, you may not be able to see
the arguments to functions etc. As sone form of optimization usually is the
default, for debugging versions I tend to switch it off explicitly, eg.
with -O0.
Also the -g (for symbols in the executable) or whatever the compiler uses
for this, usually is not part of the default settings, so I''d switch it on
for the debug versions. For gcc even -g3.

Bye, Jojo


11月12日,07:27,Tomásóhéilidhe< t ... @ lavabit.comwrote:
On 12 Nov, 07:27, Tomás ó héilidhe <t...@lavabit.comwrote:

当我正在编写自己的代码时,编译它并在我去的时候测试它

,我通常编译如下:


* * gcc * .c -ansi -pedantic -Wall -o executable


如果我我正在使用第三方库,我通常会做以下事情:


* * gcc * .c -Wall -o可执行文件


当我已经测试了我的代码并将其分发给其他人使用时,我倾向于告诉他们编译如下:

* * gcc * .c -o可执行文件

如果我的代码经过了充分测试,我确信它运行正常,我

编译如下:


* * gcc * .c -O3 -D NDEBUG -s -o可执行文件


我能理解为什么我们不使用-D NDEBUG或-s当测试

,因为我们想要捕获断言的断言,但我很好奇

是否有任何理由回避使用 -O3" (或者对于任何编译器的任何

优化)在调试版本中?
When I''m writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

* * gcc *.c -ansi -pedantic -Wall -o executable

If I''m using 3rd-party libraries, I''ll usually do the following:

* * gcc *.c -Wall -o executable

When I''ve already tested my code and I''m distributing it to other
people to use, I tend to tell them to compile as follows:

* * gcc *.c -o executable

If my code has been well-tested and I''m certain it works perfectly, I
compile as follows:

* * gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don''t use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I''m curious as to
whether there''s any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?



一般来说,最好通过不同级别的优化来运行你的测试套件多次b / b
。如果你使用调试器,

,当优化开启时可能会很痛苦,这通常是为什么它们被关闭进行测试的原因。但是这也是不好的想法,也不用优化测试。


IOW,同时运行:


配置CFLAGS =" -g" &安培;&安培; make check

**和**

配置CFLAGS =" -g -O3" &安培;&安培;检查


(或者,在你的情况下,手动编译并运行你的测试套件

两个优化级别。祈祷你不需要

在优化版本上使用调试器。)


Generally, it is a good idea to run your testsuite multiple
times with optimizations of different levels. If you use a debugger,
it can be painful when optimizations are on and that is
typically why they get turned off for testing. But it is
a bad idea not to test with the optimization on as well.

IOW, run both:

configure CFLAGS="-g" && make check
** and **
configure CFLAGS="-g -O3" && make check

(or, in your case, compile by hand and run your test suite
with both levels of optimization. Pray you don''t need
to use a debugger on the optimized version.)


在文章< 97 ************ ********************** @ c22g2000prc。 googlegroups.com>,
$ b $bTomásóhéilidhe< to*@lavabit.comwrote:
In article <97**********************************@c22g2000prc. googlegroups.com>,
Tomás ó héilidhe <to*@lavabit.comwrote:

>我能理解为什么我们不' 使用-D NDEBUG或-s在测试时因为我们想要捕获断言,但我很好奇
是否有任何理由回避使用-O3 (或任何编译器对此问题的任何优化)在调试版本中?
>I can understand why we don''t use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I''m curious as to
whether there''s any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?



我强烈建议在编译新代码时使用一些优化,

,因为gcc(和其他编译器)通常可以在
他们优化。例如。优化可能导致更多的分析变量使用
,允许编译器警告未经检测的未初始化的

变量。


另一方面,优化可以使调试器的工作效果不佳,通常因为变量在优化的

版本中没有实际存在。


一般我用-O编译并在没有它的情况下重新编译如果它导致

调试问题。


- Richard

-

请记得提及我/你留下的录音带。

I strongly recommend using some optimisation when compiling new code,
because gcc (and other compilers) can often give better warnings when
they optimise. For example. optimisation may result in more analysis
of variable use, allowing the compiler to warn about an uninitialised
variable that it would not otherwise detect.

On the other hand, optimisation can make debuggers work less well,
often because a variable has no real existence in the optimised
version.

Generally I compile with -O and recompile without it if it causes
debugging problems.

-- Richard
--
Please remember to mention me / in tapes you leave behind.


这篇关于编译“发行版本”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆