cmusphinx / sphinxtrain

Acoustic model trainer for CMU Sphinx
Other
178 stars 112 forks source link

macOS compilation error: lexicon.c:202:12: error: implicit declaration of function 'str2words' is invalid in C99 #27

Open lsonnino opened 2 years ago

lsonnino commented 2 years ago

I am unable to compile the code on macOS 12.1 Monterey. After running ./configure, the make commands fails:

Making all in libcommon
/bin/sh ../../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../include   -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include  -I../../../include -g -O2 -fPIC -DPIC -MT lexicon.lo -MD -MP -MF .deps/lexicon.Tpo -c -o lexicon.lo lexicon.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../../include -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include -I../../../include -g -O2 -fPIC -DPIC -MT lexicon.lo -MD -MP -MF .deps/lexicon.Tpo -c lexicon.c  -fno-common -DPIC -o .libs/lexicon.o
lexicon.c:202:12: error: implicit declaration of function 'str2words' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        n_phone = str2words(line->buf, NULL, 0) - 1;
                  ^
1 error generated.
make[3]: *** [lexicon.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive] Error 1

I have both Perl v5.30.3 (which is installed by default on macOS) and Python 3.9.7 installed. I also installed the latest version (5-prealpha) of sphinxbase and pocketsphinx through code compilation (sudo make install) and I have the compiled source code of both in folders named sphinxbase and pocketsphinx respectively in the same parent folder as my sphinxtrain folder I am trying to compile. (The absolute path to those folders does not contain any spaces, as this seem to be an issue as well.)

Finally, adding #include <sphinxbase/strfuncs.h> to src/libs/libcommon/lexicon.c and src/libs/libcommon/mk_phone_seq.c seems to solve the problem, however another error occurs:

Making all in libio
/bin/sh ../../../libtool  --tag=CC   --mode=compile gcc -DHAVE_CONFIG_H -I. -I../../../include   -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include  -I../../../include -g -O2 -fPIC -DPIC -MT corpus.lo -MD -MP -MF .deps/corpus.Tpo -c -o corpus.lo corpus.c
libtool: compile:  gcc -DHAVE_CONFIG_H -I. -I../../../include -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include -I/Users/lorenzo/Downloads/sphinx_install/sphinxtrain/../sphinxbase/include -I../../../include -g -O2 -fPIC -DPIC -MT corpus.lo -MD -MP -MF .deps/corpus.Tpo -c corpus.c  -fno-common -DPIC -o .libs/corpus.o
corpus.c:1314:12: error: implicit declaration of function 'areadfloat' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            ret = areadfloat(mk_filename(DATA_TYPE_MFCC, cur_ctl_path),
                  ^
corpus.c:1318:12: error: implicit declaration of function 'areadfloat_part' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
            ret = areadfloat_part(mk_filename(DATA_TYPE_MFCC, cur_ctl_path),
                  ^
corpus.c:1388:9: error: implicit declaration of function 'areadshort' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if (areadshort(mk_filename(DATA_TYPE_SEG, rel_path), (int16**)seg, n_seg) < 0)
        ^
3 errors generated.
make[3]: *** [corpus.lo] Error 1
make[2]: *** [all-recursive] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all-recursive] Error 1

I suppose adding another include would solve this problem as well but I guess this is not the way to do it. Am I missing something ?

lsonnino commented 2 years ago

After compiling the code on a Linux machine, I see the same warning except it is not turned into an error. macOS seems to add the flag -Werror by itself (maybe because of Clang ?). Any idea ?

dhdaines commented 2 years ago

Hmm, enabling -Werror by default is not a good look, but on the other hand, not enabling -Wall isn't either, which would have allowed us to catch these things...

It seems to be a compiler default as it isn't on the command-line. Since GitHub lets you run actions on Mac OS X, I may be able to test this without shelling out thousands of dollars for an unreliable computer with a glowing piece of fruit on it :) but in the meantime I'll try to get the warning flags standardized, which is suprisingly difficult to do with Autotools...