使用 GCC 和 autotools 为单个源文件设置编译标志的最佳方法是什么? [英] What is the best way to set compilation flags for individual source files using GCC and autotools?

查看:52
本文介绍了使用 GCC 和 autotools 为单个源文件设置编译标志的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 autotools 禁用单个文件的优化标志.最好的方法是什么?

I need to disable optimization flag for a individual file using autotools. What is the best way to do it?

推荐答案

你是说一个单独的源文件还是一个单独的可执行文件?

Do you mean an individual source file or an individual executable?

禁用可执行文件优化很简单:

To disable optimization for an executable is simple:

bin_PROGRAMS = myprog
myprog_SOURCES = foo.c bar.c
myprog_CFLAGS = -O0

如果您的意思是要暂时禁用对单个源文件的优化,例如出于调试目的,您可以在提示符下重新制作该文件:(来自 automake 手册的示例)

If you mean that you want to disable the optimization for a single source file temporarily, say for debugging purposes, you can just remake that file at the prompt: (example from the automake manual)

rm bar.o
make CFLAGS=-O0 bar.o
make

为单个源文件永久做这件事并不是那么简单,最好通过创建一个方便的库来完成:

To do it for an individual source file permanently is not so simple, and probably best done by creating a convenience library:

noinst_LIBRARIES = libnoopt.a
libnoopt_a_SOURCES = bar.c
libnoopt_a_CFLAGS = -O0

bin_PROGRAMS = myprog
myprog_SOURCES = foo.c
myprog_CFLAGS = -O2
myprog_LDADD = libnoopt.a

这篇关于使用 GCC 和 autotools 为单个源文件设置编译标志的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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