2

I have the following snippet in my makefile (the first line was added by me after finding it as a candidate solution online - unfortunately, it doesn't work):

$(shell set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} /usr/local/lib/python3.5/dist-packages/numpy/core/include))

all: obj $(EXEC) link
$(EXEC): $(OBJS)
    $(CC) $(COMMON) -I./src/factor $(CFLAGS) $^ -o $@ $(LDFLAGS)
    $(CC) -shared $(COMMON) -I./src/factor $(CFLAGS) $^ -o $(SHAREDLIB) $(LDFLAGS)
$(OBJDIR)%.o: %.c $(DEPS)
    $(CC) $(COMMON) -I./src/factor $(CFLAGS) -c $< -o $@

I verified that numpy/arrayobject.h is in /usr/local/lib/python3.5/dist-packages/numpy/core/include on my system. After executing make I get:

gcc -I ./include -I/usr/include/python3.5 -DGPU -I/usr/local/cuda-10.0/include/ -DCUDNN  -I./src/factor -Wall -Wfatal-errors -fPIC -Ofast -DGPU -DCUDNN -c ./src/ComputationPy.c -o obj/ComputationPy.o
./src/ComputationPy.c:12:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile:51: recipe for target 'obj/ComputationPy.o' failed
make: *** [obj/ComputationPy.o] Error 1

Line 51 corresponds to the last line of the snippet.

  • You solve this error by making sure there is such file or directory.. – Paul Ogilvie Jul 30 '20 at 13:00
  • Or by changing the reference to where it actually is. This may not be a makefile error but an include error. – Paul Ogilvie Jul 30 '20 at 13:01
  • If your sure all of the syntax is correct, but still seeing this error, then take a look at this conversation about [Cmake is not able to find Python-libraries](https://stackoverflow.com/questions/24174394/cmake-is-not-able-to-find-python-libraries) – ryyker Jul 30 '20 at 13:09
  • That `$(shell ...)` construct is not doing anything useful. If you were expecting it to add `/usr/local/lib/python3.5/dist-packages/numpy/core/include` to a Make variable called `PYTHON_INCLUDE_DIRS`, then that's your problem. Use `+=` instead. – zwol Jul 30 '20 at 13:10
  • Setting a shell variable has no effect if you don't use it. You need a `-I` in your build including that directory – stark Jul 30 '20 at 13:11
  • @stark Given the log snippet shown, I'm pretty sure `$(PYTHON_INCLUDE_DIRS)` appears somewhere in the value of COMMON. – zwol Jul 30 '20 at 13:12
  • @zwol Adding COMMON += -I /usr/local/lib/python3.5/dist-packages/numpy/core/include resolved the issue. Thank you – ScruffyFluffy Jul 30 '20 at 13:27

1 Answers1

1

Without seeing the complete Makefile it's hard to be sure what's wrong, but this line looks like it can't possibly be correct:

$(shell set(PYTHON_INCLUDE_DIRS ${PYTHON_INCLUDE_DIRS} /usr/local/lib/python3.5/dist-packages/numpy/core/include))

In GNU make, $(shell ...) runs sh -c "..." [technically, $(SHELL) -c "...") and evaluates to whatever that command prints on its stdout. set(...) is not valid sh syntax, and also, the stuff inside $(shell ...) cannot change Make variables. I would expect this line to print an error message as part of the make log, something like

sh: 1: Syntax error: word unexpected (expecting ")")

and otherwise have no effect.

Assuming the goal here is to append /usr/local/lib/python3.5/dist-packages/numpy/core/include to the value of the Make variable PYTHON_INCLUDE_DIRS, the way to do that is with +=:

PYTHON_INCLUDE_DIRS += /usr/local/lib/python3.5/dist-packages/numpy/core/include

The rules you quoted don't directly make use of this variable, but I suspect there may be a reference to it hiding inside $(COMMON).

zwol
  • 135,547
  • 38
  • 252
  • 361