Can't turn off gcc optimizer, Makefile from automake
Asked Answered
P

1

12

I am trying to get ZBar in a debug session. I am able to do so, but I can't get the optimizer to turn off, so my debug session jumps around unexpectedly and many variables are labeled as optimized-out in Eclipse Indigo. I am running in Ubuntu.

I have tried adding -O0 as far right in any gcc call in the Makefiles as possible, since the last -O is the acting one. I used -Q --help=optimizers to find what to be looking for, but its output is a bit odd:

libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I./include -I./zbar -I./include -O0 -O0 -Q --help=optimizers -Wall -Wno-parentheses -O0 -g -O0 -Q --help=optimizers -MT zbar/zbar_libzbar_la-config.lo -MD -MP -MF zbar/.deps/zbar_libzbar_la-config.Tpo -c zbar/config.c  -fPIC -DPIC -o zbar/.libs/zbar_libzbar_la-config.o
The following options control optimizations:
make[1]: *** [zbar/zbar_libzbar_la-config.lo] Error 1
  -O<number>                        
make: *** [all] Error 2
  -Ofast                            
  -Os                               
  -falign-functions                 [disabled]
  -falign-jumps                     [disabled]
  -falign-labels                    [disabled]
  -falign-loops                     [disabled]
  -fasynchronous-unwind-tables      [enabled]
  -fbranch-count-reg                [enabled]
  -fbranch-probabilities            [disabled]
  -fbranch-target-load-optimize     [disabled]
  -fbranch-target-load-optimize2    [disabled]
  -fbtr-bb-exclusive                [disabled]
  -fcaller-saves                    [disabled]
  -fcombine-stack-adjustments       [disabled]
  -fcommon                          [enabled]
  -fcompare-elim                    [disabled]

etc...

Obviously, I've been putting -O0 in several places. I don't have any experience with automake, which is used by ZBar. I'm trying to avoid having to make my own Makefile from scratch, are there any suggestions on where to look to disable the optimizer? I have already searched the Makefiles for all the -O's and any -f's related to optimization; I've found none. The project was cleaned after the Makefile modification attempts were made.

Procession answered 15/3, 2012 at 17:47 Comment(0)
T
31

Disabling optimizations can most easily be done when you run configure, or when you run make. Either

configure CFLAGS='-g -O0' CXXFLAGS='-g -O0'

or

make CFLAGS='-g -O0' CXXFLAGS='-g -O0' clean all

should do what you want. If you set CFLAGS/CXXFLAGS during configure, those values will be used for all invocations of make that do not override them, while setting them at make time is a one-time deal.

Tourniquet answered 15/3, 2012 at 17:50 Comment(6)
Neither have an effect. Note that I am not the author of the code, and am simply trying to complete an algorithm analysis. Putting the -O0 with the make call puts that -O0 in front of any other flag to enable optimization, making it non-effective. I don't see any optimization flags being set in the thousands of lines of Makefile code...Procession
CFLAGS should be the very last item set in COMPILE in the makefile, so unless the package maintainer is overriding your attempt to set CFLAGS (which should be reported as a bug) your setting should be last. If you do "CFLAGS=-this-option-is-an-error", does that option appear during compilation?Tourniquet
When I add the false flag I get: gcc: error: unrecognized option ‘-this-option-is-an-error’Procession
I've just given a cursory look at the zbar autotool setup, and it looks correct. It is possible that the optimization flags you are seeing are coming from pkg-config. It would help if you provided a sample output from make that shows the actual flags you are trying to avoid.Tourniquet
Look here under attached filesProcession
Are you running make clean before make CFLAGS='-O0 -g'?Limnetic

© 2022 - 2024 — McMap. All rights reserved.