user2447581 user2447581 - 3 months ago 27
C++ Question

Linux MAKEFILE access environment variable

I install OpenCV library in Linux. If I run command:

echo $(pkg-config --libs opencv)


The result is as follow:
enter image description here

But if I run it from MAKEFILE like this:

all:
@echo 1
@echo $(pkg-config --libs opencv)
@echo 2


Nothing is print out, what happend?
enter image description here

Answer

You forgot shell in your shell commands: https://www.gnu.org/software/make/manual/html_node/Shell-Function.html

Try this:

@echo $(shell pkg-config --libs opencv)

With it, you were printing the value of a variable named pkg-config (or something like that).