2

I've built a script to automate a CMake build of OpenCV4. The relevant part of the script is written as:

install.sh

#!/bin/bash
#...
cd /home/pi/opencv
mkdir build
cd build

cmake -D CMAKE_BUILD_TYPE=RELEASE \
    -D CMAKE_INSTALL_PREFIX=/usr/local \
    -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
    -D ENABLE_NEON=ON \
    -D ENABLE_VFPV3=ON \
    -D BUILD_TESTS=OFF \
    -D OPENCV_ENABLE_NONFREE=ON \
    -D INSTALL_PYTHON_EXAMPLES=ON \
    -D BUILD_EXAMPLES=OFF ..

This part of the code is first executed from /home/pi/ directory. If I execute these lines within the cli they work and the cmake file is built without error. If I run this same code form a bash script it results in the cmake command resulting in -- Configuring incomplete, errors occurred!.

I believe this is similar to these two SO threads (here and here) in as much as they both describe situations where calling a secondary script from the first script creates a problem (or at least that's what I think they are saying). If that is the case, how can you start a script from /parent/, change to /child/ within the script, execute secondary script (CMake) as though executed from the /child/ directory?

If I've missed my actual problem - highlighting taht would be even more helpful.

Update with Full Logs

Output log for CMakeOutput.log and CMakeError.log as unsuccessfully run from the bash script.

When executed from the cli the successful logs are success_CMakeOutput.log and success_CMakeError.log

Update on StdOut

I looked through the files above and they look the same... Here is the failed screen output (noting the bottom lines) and the successful screen output.

Bill Armstrong
  • 1,615
  • 3
  • 23
  • 47
  • 3
    Message `-- Configuring incomplete, errors occurred!` means that some error(s) has occurred **before**. By itself, such message is not useful for debug the problem. Please, show us the message describing the first error. – Tsyvarev Nov 28 '19 at 07:53
  • You could explicitely add the source and build directories to the CMake call with `-S` and `-B` options. Maybe that helps. – vre Nov 28 '19 at 15:18
  • Diagnostic: compare output of `env` from shell against output within script. Any differences may be relevant. – bishop Nov 28 '19 at 19:40
  • @bishop - yep, I was only focused on the failed logs... I've attached both, but haven't yet (doing in now) compared. – Bill Armstrong Nov 28 '19 at 20:09
  • `http://%3Cscript%20src=%22https://gist.github.com/Llibyddap/0fd16fe5b5a73675ad28244174fa6014.js%22%3E%3C/script%3E` - your links look invalid. Also, just in case, please __don't__ post links to text, this looks like a link to `gist.github`. Post the relevant text/messages in the question instead. I mean, the error is rather easy to find: `CMake Error at cmake/OpenCVModule.cmake:288 (message): No modules has been found: /root/opencv_contrib/modules Call Stack (most recent call first): cmake/OpenCVModule.cmake:370 (_glob_locations) modules/CMakeLists.txt:7 (ocv_glob_modules)`.... – KamilCuk Nov 28 '19 at 20:58
  • @KamilCuk - you're right - it is a gist, but the files are +1000 lines... :-s. I think you're right on the error - i think that it is running from the `/` directory when from the script but from the `build` directory when I do it from the cli. That's why I think the issue is the working directory not being passed to the CMake script... ? Will do - on your follow comment - thanks. – Bill Armstrong Nov 28 '19 at 21:03
  • This looks like you didn't remove the build directory before running cmake, so it picks the old cache. Remove CMakeCache.txt file or the build directory before re-configuring. And _please_ update your post to include the relevant information _as text_ in the question. It will help others that will try to search for the same problem _on this site_. `files are +1000 lines` - the whole output is not relevant - the error message has like 5 ilnes. Did you clean the build directory before running cmake? How does `/root/opencv_contrib` end up in the logs? Are you running your script as root? – KamilCuk Nov 28 '19 at 21:03
  • The `~/opencv_contrib/modules` references a user home directory, if `opencv_contrib` is in `/home/pi`, then replace the `~` with `/home/pi`. Or run it as a user that has proper `HOME` with that `opencv_contrib` folder. Exactly, the output from the success is `/home/pi/opencv_contrib/modules`, you are running your script as a different user, so the path to opencv_contrib is invalid.... – KamilCuk Nov 28 '19 at 21:07

1 Answers1

1

You are running your script as the root user with the /root home directory, while the opencv_contrib directory is in /home/pi directory. The /home/pi is most probably the home directory of the user pi.

Update the:

-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \

With proper path to opencv_contrib. Either provide opencv_contrib in the home directory of the root user, if you aim to run the script as root, or provide full, non-dependent on HOME, path to opencv_contrib directory.

-D OPENCV_EXTRA_MODULES_PATH=/home/pi/opencv_contrib/modules \
KamilCuk
  • 120,984
  • 8
  • 59
  • 111