G ++: & ldquo; Order not found & rdquo; After you declare variables in Bash

advertisements

The g++ command doesn't work after declaring a variable before the g++ command.

For example, the following works:

echo "Train LINE starts"
g++ -lm -pthread -Ofast -march=native -Wall -funroll-loops -ffast-math -Wno-unused-result line.cpp -o line -lgsl -lm -lgslcblas

But this does not:

PATH="foo path"
echo "Train LINE starts"
g++ -lm -pthread -Ofast -march=native -Wall -funroll-loops -ffast-math -Wno-unused-result line.cpp -o line -lgsl -lm -lgslcblas

Instead, I get an error: g++: command not found. Is it the correct way of declaring variables?


The PATH environment variable consists of a colon-delimited list of directories. The shell searches for executable files in these directories in response to commands issued by a user.

For example, if g++ executable is located in /usr/bin directory, then you can implicitly call /usr/bin/g++ only if PATH contains /usr/bin:

echo $PATH
/usr/bin:/bin:/opt/bin

If you want to add a search path, you should append it to the existing value of the variable:

PATH="$PATH:/new/search/path"