简体   繁体   中英

Execution CMake from within a Bash Script

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 .

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 \

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM