What is the best way to set compilation flags for individual source files using GCC and autotools?

做~自己de王妃 提交于 2019-12-10 07:28:03

问题


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


回答1:


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

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


来源:https://stackoverflow.com/questions/2220855/what-is-the-best-way-to-set-compilation-flags-for-individual-source-files-using

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!