freeswitch/spandsp

Cannot Make

ranmeng-china opened this issue · 6 comments

ademco_contactid.c:452:51: error: initializer element is not a compile-time constant static const float detection_threshold = goertzel_threshold_dbm0(GOERTZEL_SAMPLES_PER_BLOCK, -42.0f); ./spandsp/tone_detect.h:66:49: note: expanded from macro 'goertzel_threshold_dbm0' #define goertzel_threshold_dbm0(len,thresh) (float) ((len*len*32768.0*32768.0/2.0)*pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0)) ademco_contactid.c:453:77: error: initializer element is not a compile-time constant static const float tone_to_total_energy = GOERTZEL_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f);

you should provide the OS gcc version etc...

This happens at least on macOS Sonoma (14.x) with Xcode 15.

> make
Making all in src
/Applications/Xcode.app/Contents/Developer/usr/bin/make  all-am
/bin/sh ../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I.  -I..  -I/libtiff -DNDEBUG -Wunused-but-set-variable -D_XOPEN_SOURCE=700 -std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes  -I/opt/homebrew/include  -MT ademco_contactid.lo -MD -MP -MF .deps/ademco_contactid.Tpo -c -o ademco_contactid.lo ademco_contactid.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I.. -I/libtiff -DNDEBUG -Wunused-but-set-variable -D_XOPEN_SOURCE=700 -std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -I/opt/homebrew/include -MT ademco_contactid.lo -MD -MP -MF .deps/ademco_contactid.Tpo -c ademco_contactid.c  -fno-common -DPIC -o .libs/ademco_contactid.o
ademco_contactid.c:452:51: error: initializer element is not a compile-time constant
static const float detection_threshold          = goertzel_threshold_dbm0(GOERTZEL_SAMPLES_PER_BLOCK, -42.0f);
                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./spandsp/tone_detect.h:66:49: note: expanded from macro 'goertzel_threshold_dbm0'
#define goertzel_threshold_dbm0(len,thresh)     (float) ((len*len*32768.0*32768.0/2.0)*pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0))
                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ademco_contactid.c:453:77: error: initializer element is not a compile-time constant
static const float tone_to_total_energy         = GOERTZEL_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f);
                                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
make[2]: *** [ademco_contactid.lo] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

Seems to be a GCC extension to allow this.

I have also encountered this problem recently. Is there any way to solve it?

OS : Apple M1 Pro. macos sonoma 14.1

`
$ make
Making all in src
/Library/Developer/CommandLineTools/usr/bin/make all-am
/bin/sh ../libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/jpeg/include -DNDEBUG -Wunused-but-set-variable -D_XOPEN_SOURCE=700 -std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -MT ademco_contactid.lo -MD -MP -MF .deps/ademco_contactid.Tpo -c -o ademco_contactid.lo ademco_contactid.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I/opt/homebrew/Cellar/libtiff/4.6.0/include -I/opt/homebrew/opt/jpeg/include -DNDEBUG -Wunused-but-set-variable -D_XOPEN_SOURCE=700 -std=c99 -Wall -Wunused-variable -Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -MT ademco_contactid.lo -MD -MP -MF .deps/ademco_contactid.Tpo -c ademco_contactid.c -fno-common -DPIC -o .libs/ademco_contactid.o
ademco_contactid.c:452:51: error: initializer element is not a compile-time constant
static const float detection_threshold = goertzel_threshold_dbm0(GOERTZEL_SAMPLES_PER_BLOCK, -42.0f);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./spandsp/tone_detect.h:66:49: note: expanded from macro 'goertzel_threshold_dbm0'
#define goertzel_threshold_dbm0(len,thresh) (float) ((lenlen32768.0*32768.0/2.0)pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ademco_contactid.c:453:77: error: initializer element is not a compile-time constant
static const float tone_to_total_energy = GOERTZEL_SAMPLES_PER_BLOCK
db_to_power_ratio(-0.85f);
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
make[2]: *** [ademco_contactid.lo] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

$ uname -a
Darwin iamtsm.local 23.1.0 Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000 arm64
`

I have also encountered this problem recently. Is there any way to solve it?

I went back to a really old version from 2016 or so that I had used before and which worked well for my simple needs. Back then it still compiled ok on other compilers.

The commit in question is 5394b2c. It replaced literals by expressions for initialization of some values. Gcc includes builtin functions for pow10f and the like, but Clang does not—unfortunately.

Could you rename the issue to »Fails to build with CLang«?

Maybe it's possible to move all these initialization values to a file that can be generated with a little tool. Possibly with a configure option --with-rebuild-init-values. But this file should be fixed and included in git.