KineticPreProcessor / KPP

The KPP kinetic preprocessor is a software tool that assists the computer simulation of chemical kinetic systems
GNU General Public License v3.0
21 stars 11 forks source link

[BUG/ISSUE] malloc.h file not found error when building KPP on MacOSX #15

Closed yantosca closed 2 years ago

yantosca commented 2 years ago

I tried building KPP locally on my MacOS laptop (with XQuartz) using gcc 11.2.0 and I get this error:

scan.y:40:12: fatal error: 'malloc.h' file not found

I looked online (see https://stackoverflow.com/questions/56463049/should-mac-osx-have-a-malloc-h-file) and it seems that the issue might be that malloc.h is now deprecated. The post suggests to use stdlib.h instead. This might be a quick way to fix it cross-platform. I am not as familiar with C as I am with Fortran so I defer to your judgment @laestrada @RolfSander @msl3v.

RolfSander commented 2 years ago

I think you can simply remove the

#include <malloc.h>

line as long as you have

#include <stdlib.h>

somewhere. I think you'll also have to fix this for scanutil.c and y.tab.c

laestrada commented 2 years ago

I agree with @RolfSander. Thanks for finding this Bob!

yantosca commented 2 years ago

I took out the instances of #include <malloc.h> and recompiled, but now I get these errors. I wonder if it's because gcc 11.2.0 skews to the newer C99 standard rather than C89:

    gcc -g -Wall -c y.tab.c
y.tab.c:1631:16: error: implicit declaration of function 'yylex' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
      yychar = YYLEX;
               ^
y.tab.c:987:16: note: expanded from macro 'YYLEX'
# define YYLEX yylex ()
               ^
scan.y:102:7: error: implicit declaration of function 'CmdJacobian' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdJacobian( (yyvsp[(2) - (2)].str) );
      ^
scan.y:105:7: error: implicit declaration of function 'CmdHessian' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdHessian( (yyvsp[(2) - (2)].str) );
      ^
scan.y:108:7: error: implicit declaration of function 'CmdDeclareValues' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdDeclareValues( (yyvsp[(2) - (2)].str) );
      ^
scan.y:111:7: error: implicit declaration of function 'CmdStoicmat' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdStoicmat( (yyvsp[(2) - (2)].str) );
      ^
scan.y:114:7: error: implicit declaration of function 'CmdDouble' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdDouble( (yyvsp[(2) - (2)].str) );
      ^
scan.y:117:7: error: implicit declaration of function 'CmdReorder' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdReorder( (yyvsp[(2) - (2)].str) );
      ^
scan.y:120:7: error: implicit declaration of function 'CmdMex' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdMex( (yyvsp[(2) - (2)].str) );
      ^
scan.y:123:7: error: implicit declaration of function 'CmdDummyindex' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdDummyindex( (yyvsp[(2) - (2)].str) );
      ^
scan.y:126:7: error: implicit declaration of function 'CmdEqntags' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdEqntags( (yyvsp[(2) - (2)].str) );
      ^
scan.y:129:7: error: implicit declaration of function 'CmdFunction' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdFunction( (yyvsp[(2) - (2)].str) );
      ^
scan.y:132:7: error: implicit declaration of function 'CmdStochastic' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdStochastic( (yyvsp[(2) - (2)].str) );
      ^
scan.y:165:7: error: implicit declaration of function 'CheckAll' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CheckAll(); ;}
      ^
scan.y:167:7: error: implicit declaration of function 'LookAtAll' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { LookAtAll(); ;}
      ^
scan.y:169:7: error: implicit declaration of function 'TransportAll' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { TransportAll(); ;}
      ^
scan.y:179:7: error: implicit declaration of function 'CmdUse' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdUse( (yyvsp[(2) - (2)].str) ); ;}
      ^
scan.y:181:7: error: implicit declaration of function 'CmdLanguage' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { CmdLanguage( (yyvsp[(2) - (2)].str) ); ;}
      ^
scan.y:183:7: error: implicit declaration of function 'DefineInitializeNbr' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { DefineInitializeNbr( (yyvsp[(2) - (2)].str) ); ;}
      ^
scan.y:185:7: error: implicit declaration of function 'DefineXGrid' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
    { DefineXGrid( (yyvsp[(2) - (2)].str) ); ;}
      ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[1]: *** [y.tab.o] Error 1

I think with gcc you can specify older standards with e.g. -std=c89 so I might try that. Any other thoughts would be appreciated.

yantosca commented 2 years ago

Also note, due to MacOSX installing Clang as /usr/bin/gcc, I had to add the following aliases into my environment, so that it would call the GCC 11 compilers in /usr/local/bin. Homebrew installed the compiler executables with the -11 suffix:

alias gcc=gcc-11
alias g++=g++-11
alias gfortran=gfortran-11
yantosca commented 2 years ago

We can now close this issue as it has been fixed by PR #17.