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

强颜欢笑 提交于 2019-12-05 17:57:22

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