I am trying to obtain opencv on my raspberry pi 3B. I noticed there is no official guide for this so I am following the linux guide on the opencv website.

and as many others have encountered, libtbb is unavailable. I read from this stack exchange thread that it is unnecessary but beneficial for my multi core chip, so I still want it.

I followed the step:

# Download and unpack
wget https://www.threadingbuildingblocks.org/sites/default/files/software_releases/source/tbb43_20150611oss_src.tgz
tar xvf tbb43_20150611oss_src.tgz
cd tbb43_20150611oss

# Make flags from https://software.intel.com/en-us/forums/topic/500680

# Export the required environment variables
cd ~/tbb43_20150611oss/build/linux_armv7_gcc_cc4.6_libc2.13_kernel3.18.11_release
source tbbvars.sh

Downloading and building was smooth, however somehow stuck at the last step.

I understand it being a bash script that generates certain environmental variable necessary for compilation of opencv. However it doesn't seem to take effect, situation goes as this.

I examined the script, it looks like this:

export TBBROOT="/home/mytbbroot" #
if [ -z "$CPATH" ]; then #
    export CPATH="${TBBROOT}/include" #
else #
    export CPATH="${TBBROOT}/include:$CPATH" #
fi #
if [ -z "$LIBRARY_PATH" ]; then #
    export LIBRARY_PATH="${tbb_bin}" #
else #
    export LIBRARY_PATH="${tbb_bin}:$LIBRARY_PATH" #
fi #
if [ -z "$LD_LIBRARY_PATH" ]; then #
    export LD_LIBRARY_PATH="${tbb_bin}" #
else #
    export LD_LIBRARY_PATH="${tbb_bin}:$LD_LIBRARY_PATH" #
fi #

I figured that it would at least add the env var TBBROOT=/home/mytbbroot/, however even I have set the script to chmod 755, and run it directly from its current directory, when I examine env, using either env or env | grep TBB, the TBBROOT does not show. I have tried running the script by both bash and sh but both yield no env.

Strangely, if I run the command directly export TBBROOT=/home/mytbbroot/, then it actually adds the env var, I verified that multiple times.

So my question(s)

  1. was there something about the script that was not correct?
  2. is there anyway to ask bash or sh to be verbose and tell me whats wrong in the script? or
  3. On top of that, which ,bashrc script should I ask the pi to put the execution in? Pi, User or root? I am using realvnc server, xserver-xorg, both Pi and user is in sudo group.


My bad, misread the thread, the script has to be ran by source, not sh.

putting source /root/tbbvars/ into .bashrc generated correct environment, question can be closed now.

  • I am not sure. The solution to the problem is to read posts correctly. What I got out of this was the knowledge that there is some program called source that also runs script. What I would love to drill on, is the difference between bash script and source script, why they look synatically alike but why bash fails to run source script, but that seemed a bit off topic, and I currenly don't have an answer. Perhaps if someone can state that it is a source script, not a bash script, and presents the corresponding bash script with explanation, that will be the perfect and complete solution. – Jimmy Chi Kin Chau Jul 18 '17 at 3:43

The step you got stuck on is this one:

source tbbvars.sh

But then, some remarks in your question hint that you did not follow that exactly:

  • You tried to execute it with bash tbbvars.sh or sh tbbvars.sh
  • You tried to execute it with ./tbbvars.sh

These are all different from source. What source does is execute code in the current process. All the above methods execute the script in a different process.

The purpose of this script is to export variables. Exported variables are visible in the current shell and in child processes. So if the exporting happens in a different process, the variables will only be visible to that process and its children.

That's not what you want here. You need those variables visible in the current shell. That's why you need to source tbbvars.sh instead of executing it. (Btw, a synonym to source is ., so . tbbvars.sh is the same thing.)

Your Answer

