Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fail: incorrect -I order causes wrong .h to load #110

Open
dmacks opened this issue Dec 12, 2019 · 1 comment
Open

Build fail: incorrect -I order causes wrong .h to load #110

dmacks opened this issue Dec 12, 2019 · 1 comment

Comments

@dmacks
Copy link

dmacks commented Dec 12, 2019

Building mpb-1.9.0 on OS X, with guile and gcc supplied by fink (older machine, so older versions of those), fails:

  CC       mpb-medium.o
In file included from /sw/include/guile/2.0/libguile/__scm.h:479:0,
                 from /sw/include/guile/2.0/libguile.h:31,
                 from /sw/include/ctl.h:28,
                 from ./ctl-io.h:7,
                 from mpb.h:22,
                 from medium.c:27:
/sw/include/guile/2.0/libguile/gc.h: In function 'scm_cell':
/sw/include/guile/2.0/libguile/gc.h:51:33: warning: cast from function call of type 'void *' to non-matching type 'long unsigned int' [-Wbad-function-cast]
 #  define PTR2SCM(x) (SCM_PACK ((scm_t_bits) (x)))
                                 ^
/sw/include/guile/2.0/libguile/tags.h:105:32: note: in definition of macro 'SCM_PACK'
 #   define SCM_PACK(x) ((SCM) (x))
                                ^
/sw/include/guile/2.0/libguile/gc.h:232:14: note: in expansion of macro 'PTR2SCM'
   SCM cell = PTR2SCM (SCM_GC_MALLOC (sizeof (scm_t_cell)));
              ^
/sw/include/guile/2.0/libguile/gc.h: In function 'scm_double_cell':
/sw/include/guile/2.0/libguile/gc.h:51:33: warning: cast from function call of type 'void *' to non-matching type 'long unsigned int' [-Wbad-function-cast]
 #  define PTR2SCM(x) (SCM_PACK ((scm_t_bits) (x)))
                                 ^
/sw/include/guile/2.0/libguile/tags.h:105:32: note: in definition of macro 'SCM_PACK'
 #   define SCM_PACK(x) ((SCM) (x))
                                ^
/sw/include/guile/2.0/libguile/gc.h:250:7: note: in expansion of macro 'PTR2SCM'
   z = PTR2SCM (SCM_GC_MALLOC (2 * sizeof (scm_t_cell)));
       ^
/sw/include/guile/2.0/libguile/gc.h: In function 'scm_words':
/sw/include/guile/2.0/libguile/gc.h:51:33: warning: cast from function call of type 'void *' to non-matching type 'long unsigned int' [-Wbad-function-cast]
 #  define PTR2SCM(x) (SCM_PACK ((scm_t_bits) (x)))
                                 ^
/sw/include/guile/2.0/libguile/tags.h:105:32: note: in definition of macro 'SCM_PACK'
 #   define SCM_PACK(x) ((SCM) (x))
                                ^
/sw/include/guile/2.0/libguile/gc.h:289:7: note: in expansion of macro 'PTR2SCM'
   z = PTR2SCM (SCM_GC_MALLOC (sizeof (scm_t_bits) * n_words));
       ^
medium.c: In function 'make_medium':
medium.c:48:6: warning: implicit declaration of function 'CHK_MALLOC' [-Wimplicit-function-declaration]
      CHK_MALLOC(m.subclass.medium_data, medium, 1);
      ^
medium.c:48:41: error: expected expression before 'medium'
      CHK_MALLOC(m.subclass.medium_data, medium, 1);
                                         ^

If I make V=1, I see the compiler call is:

gcc-fsf-5 -DHAVE_CONFIG_H -I. -I.. -I../src -I/sw/include/guile/2.0 -I/sw/include -D_THREAD_SAFE -I../src/util -I../src/matrices -I../src/matrixio -I../src/maxwell -DHAVE_CTL_HOOKS=1 -DHAVE_CTL_EXPORT_HOOK=1 -DCTL_SCM='"'/sw/share/libctl/base/ctl.scm'"' -DINCLUDE_SCM='"'/sw/share/libctl/base/include.scm'"' -DSPEC_SCM='"'/sw/share/mpb/mpb.scm'"' -DVERSION_STRING='"'"mpb 1.9.0, Copyright (C) 1999-2012, MIT"'"' -DH5_USE_16_API=1 -MD -I/sw/include -g -O2 -Wall -W -Wbad-function-cast -Wcast-qual -Wpointer-arith -Wcast-align -pedantic -Wno-unused-but-set-variable -MT mpb-medium.o -MD -MP -MF .deps/mpb-medium.Tpo -c -o mpb-medium.o `test -f 'medium.c' || echo './'`medium.c

I have a /sw/include/check.h from some other package, which is what's being #included, rather than the intended ../src/util/check.h, because -I/sw/include is ahead of -I../src/util. To make sure local headers are loaded regardless of what things might be installed externally, all local -I should come before external ones. So...

  • In mpb/Makefile.am, MY_CPPFLAGS should have $(GUILE_CPPFLAGS) at the end not the beginning.
  • In utils/Makefile.am, mpb@MPB_SUFFIX@_data_CPPFLAGS should have $(CTLGEOM_H_CPPFLAG) at the end not the beginning.
@stevengj
Copy link
Collaborator

Thanks, a PR would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants