Reputation: 452
I have this command that compiles my program.
c++ -O3 -Wall -shared -pthread -std=c++11 -fPIC $(python3 -m pybind11 --includes) f1.cpp f2.cpp -o exemple$(python3-config --extension-suffix)
I created the following Makefile.
test:
c++ -O3 -Wall -shared -pthread -std=c++11 -fPIC $(python3 -m pybind11 --includes) f1.cpp f2.cpp -o exemple$(python3-config --extension-suffix)
The command will succeed if ran from terminal but make will fail.
It fails with the error
pybind11/pybind11.h: No such file or directory
1 | #include <pybind11/pybind11.h>
This file is supposed to be imported with $(python3 -m pybind11 --includes)
in the command.
I thought that commands in Makefile were executed much like a bash script.
What are the differences between running a command in bash and running a command in a Makefile ?
Upvotes: 0
Views: 110
Reputation: 3767
Another variant $(shell bash_command)
test:
c++ -O3 -Wall -shared -pthread -std=c++11 -fPIC $(shell python3 -m pybind11 --includes) f1.cpp f2.cpp -o exemple$(shell python3-config --extension-suffix)
Upvotes: 2
Reputation: 38539
The more portable way of inserting a command result as a part of the current command in shell is using `` instead of $(python3 -m pybind11 --includes)
. Make does not interpret such quotes.
test:
c++ -O3 -Wall -shared -pthread -std=c++11 -fPIC `python3 -m pybind11 --includes` f1.cpp f2.cpp -o exemple`python3-config --extension-suffix`
Upvotes: 1
Reputation: 100856
Makefiles run commands in /bin/sh
(by default). That can sometimes make a difference, if you're using bash features; but you're not so that doesn't matter.
The issue here is that the $
character is special to make: it introduces make variables. If you want to pass a $
to the shell you have to double it:
test:
c++ -O3 -Wall -shared -pthread -std=c++11 -fPIC $$(python3 -m pybind11 --includes) f1.cpp f2.cpp -o exemple$$(python3-config --extension-suffix)
Upvotes: 2