I have read this, which suggests the following compilation check:
installCheck () {
if g++ check_opencv.cpp -o check_opencv; then
return 1
else
rm check_opencv
return 0
fi
}
if installCheck $0; then
echo "OpenCV already installed, skipping"
exit 0
fi
However, running this script gives:
check_opencv.cpp:2:33: fatal error: opencv2/core/core.hpp: No such file or directory
compilation terminated.
rm: check_opencv: No such file or directory
OpenCV already installed, skipping
which is wrong. Then I change to this:
installCheck () {
g++ check_opencv.cpp -o check_opencv
if [[ $? -ne 0 ]]; then
and it works fine:
check_opencv.cpp:2:33: fatal error: opencv2/core/core.hpp: No such file or directory
compilation terminated.
Cloning into 'opencv-2.4.9'...
Why is that? Because of some behavior of [[
or g++
?
Someone in this says that "Sadly as it turns out make returns 0 weather or not it fails." Shouldn't g++
always return non-zero value when it fails? Maybe I miss something obvious, so please clarify for me. Thank you very much!
Update: it turns out that I understand bash wrongly. A return value of 0 evaluates to true in bash, which is contradictory to what I thought before. This helps.