2

I'm trying to compile an open source project on windows under mingw/msys.

The makefile contains (among others) this line

@${MAKE} --no-print-directory -C . -f physfs.make

physfs.make contains (among others) these lines:

ifndef CC
  CC = gcc
endif

when I ran make I get the following error:

Creating obj/Debug/physfs
physfs.c
make[1]: cc: Command not found
make[1]: *** [obj/Debug/physfs/physfs.o] Error 127
make: *** [physfs] Error 2

If I comment the ifndef / endif pair leaving CC = gcc intact, the build works. If instead of make I issue this command:

make -e CC=gcc

the build works as well. But when I run the following command in msys:

echo $CC

nothing is displayed.

I think there is something basic about how environment variables work in MSYS and make that I don't understand.

Could please some help me troubleshoot this issue, so I can understand why simple 'make' command complains and why the ifndef block doesn't function as I expect it to function.

1 Answer 1

1

CC is one of several implicit variables automatically defined in a make session, so the line ifndef CC should never evaluate to true.

This explains why you see nothing on the command line for echo $CC. The MSYS environment has no concept of CC.

If you want to see the value of variables from within a make session, you can always use the info function:

$(info $(CC))

This will echo the value of the CC variable to the console at the point when that line in the makefile is evaluated.

5
  • 2
    Remark: the correct way to test if $(CC) has the default value would be ifeq (default,$(origin CC)).
    – Jack Kelly
    Oct 27, 2010 at 1:48
  • @Jack Kelly: The make file is generated by premake utility industriousone.com/premake so I can't change what is being generated. On the premake website someone maintained that it's a bug in mingw-make, that CC by default equals to cc. The gnu man that e.James linked seems to suggest otherwise. Oct 27, 2010 at 3:27
  • @zespri: The link that I posted agrees: CC is set to cc by default.
    – e.James
    Oct 27, 2010 at 12:42
  • If I understood your last comment correctly, then this is what I meant too. Someone said (industriousone.com/post/…) that mingw-make sets CC to a wrong value, and the link you gave suggests that setting CC to cc by default is how it was intended. Oct 27, 2010 at 18:08
  • @zespri: Yes, we are saying the same thing. I had misunderstood your previous comment; I thought you meant that my link stated that the CC variable was not supposed to equal cc by default. I realize now that you meant the opposite :)
    – e.James
    Oct 27, 2010 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.