# ITK build with TBB

**URL:** https://discourse.itk.org/t/itk-build-with-tbb/1954
**Category:** Beginner Questions
**Created:** [June 10, 2019, 10:18am UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954 "2019-06-10T10:18:53Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 10, 2019, 10:18am UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/1 "2019-06-10T10:18:53Z")

</div>

Hi everyone,

I am trying to build ITK-5.0.0 with TBB.  
I have already successfully built TBB.  
After cmake config I get this error

```auto
 Could not find a package configuration file provided by "TBB" with any of
  the following names:

    TBBConfig.cmake
    tbb-config.cmake

  Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set "TBB_DIR"
  to a directory containing one of the above files.

```

I have tried to compile by command line also

```auto
-DCMAKE_PREFIX_PATH=/home/hs/Dcuments/TBB \
-DModule_ITKTBB:BOOL=ON \

```

still the same error.  
Can someone tell how to fix this?

Thank you

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 10, 2019, 5:22pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/2 "2019-06-10T17:22:01Z")

</div>

TBB is not a normal CMake-managed library. Instead of creating a `TBBConfig.cmake` file when you build it, they provide a way for you to generate a customized version of `TBBConfig.cmake`. But the binary release of TBB does contain `TBBConfig.cmake`, which is what you are supposed to point at when configuring ITK.

@hjmjohnson has tried to convince TBB people to add better CMake support, and might have further suggestions.

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 11, 2019, 2:37pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/3 "2019-06-11T14:37:12Z")

</div>

But ITK-4.13 did not require `TBBConfig.cmake`  
It only has `TBBFind.cmake` file.  
I want to understand what is the difference between this two versions.  
Thank you

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 11, 2019, 3:25pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/4 "2019-06-11T15:25:42Z")

</div>

Plain ITK-4.13 did not make use of TBB at all. Only the remote module `TBBImageToImageFilter` did. And the drawback of `FindTBB.cmake` approach is necessity of specifying about 20 paths for include directories and release and debug libraries for TBB components (tbb, tbb\_malloc, tbbmalloc\_proxy etc). Also, there is an outstanding [PR](https://github.com/InsightSoftwareConsortium/ITK/pull/991) which adds back `FindTBB.cmake`. It would be good if you tested and reviewed that PR - it might be a solution you are looking for.

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 13, 2019, 10:59am UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/5 "2019-06-13T10:59:44Z")

</div>

Right, but 5.0.0 version does not come with FindTBB.cmake file.  
How can I generate that file for 5.0.0 version

---

<div class="post-metadata">

### Author: ![imikejackson](https://discourse.itk.org/user_avatar/discourse.itk.org/imikejackson/32/35_2.png) [@imikejackson](https://discourse.itk.org/u/imikejackson)
#### Post date: [June 13, 2019, 12:37pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/6 "2019-06-13T12:37:29Z")

</div>

Would it be possible to use a newer version of TBB? Versions of TBB since about late 2017 come with a TBBConfig.cmake file which does away with the need for the FindTBB.cmake at all.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 13, 2019, 1:27pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/7 "2019-06-13T13:27:02Z")

</div>

@imikejackson Precompiled versions of TBB. He compiled his own.

@nm97 The [patch](https://github.com/InsightSoftwareConsortium/ITK/pull/991) should be easy to apply to 5.0.0. Try to apply it, and use such patched ITK. Then let us know how it went.

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 13, 2019, 5:40pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/8 "2019-06-13T17:40:51Z")

</div>

I am testing it right now.  
And one more question.  
When I configure with cmake it has variable with name TBB\_MALLOC\_PROXY\_LIBRARY. Is it required to give path to that file?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 13, 2019, 6:55pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/9 "2019-06-13T18:55:35Z")

</div>

I don’t know. I always gave it the paths to all the libraries that appeared in CMake cache.

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 14, 2019, 10:07am UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/10 "2019-06-14T10:07:39Z")

</div>

I applied [patch](https://github.com/InsightSoftwareConsortium/ITK/pull/991) to 5.0.0, it compiles fine, but for running examples it still causes error

```auto
CMake Error at /usr/local/lib/cmake/ITK-5.0/Modules/ITKTBB.cmake:15 (find_package):
  Could not find a package configuration file provided by "TBB" with any of
  the following names:

    TBBConfig.cmake
    tbb-config.cmake

  Add the installation prefix of "TBB" to CMAKE_PREFIX_PATH or set "TBB_DIR"
  to a directory containing one of the above files. If "TBB" provides a
  separate development package or SDK, be sure it has been installed.
Call Stack (most recent call first):
  /usr/local/lib/cmake/ITK-5.0/ITKModuleAPI.cmake:76 (include)
  /usr/local/lib/cmake/ITK-5.0/ITKModuleAPI.cmake:31 (itk_module_load)
  /usr/local/lib/cmake/ITK-5.0/ITKModuleAPI.cmake:129 (_itk_module_config_recurse)
  /usr/local/lib/cmake/ITK-5.0/ITKConfig.cmake:82 (itk_module_config)
  CMakeLists.txt:19 (find_package)

```

how can I test binareies in this case?

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 14, 2019, 12:26pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/11 "2019-06-14T12:26:12Z")

</div>

And the last question please.  
When I am building there is TBB\_DIR variable. I can not understand which directory path I have to give to that variable.  
Do you have any idea?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 14, 2019, 1:24pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/12 "2019-06-14T13:24:05Z")

</div>

On my Linux computer, `TBB_DIR` path is `/home/dzenan/tbb2019_20190206oss/cmake`. I am using [binary distribution](https://github.com/intel/tbb/releases).

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 14, 2019, 2:58pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/13 "2019-06-14T14:58:08Z")

</div>

> [@dzenanz](#):
>
> `TBB_DIR`

Just to make it clear.  
As I understand 4.13 version does not have TBB\_DIR variable, so we don’t need to have TBBConfig.cmake file.  
And 5.0.0 requires TBBConfig.cmake file.  
Am I right?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 14, 2019, 3:17pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/14 "2019-06-14T15:17:56Z")

</div>

ITK 4.13 did not have TBB support. ITK 5.0 has support for TBB, and requires `TBBConfig.cmake` which comes with newer binary distributions of TBB. TBB also has a procedure to generate `TBBConfig.cmake` for a TBB you compiled yourself, but that is not easy. [PR991](https://github.com/InsightSoftwareConsortium/ITK/pull/991) tries to alleviate the restriction of requiring `TBBConfig.cmake`.

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [June 14, 2019, 3:20pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/15 "2019-06-14T15:20:20Z")

</div>

And you don’t have to build with TBB - that is an optional feature which allows better load balancing, and is supposed to ease general parallel performance, especially when ITK-based program is not the only one making high CPU use.

---

<div class="post-metadata">

### Author: ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)
#### Post date: [June 14, 2019, 4:40pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/16 "2019-06-14T16:40:01Z")

</div>

Right,  
I have tried this version already, the problem is I can not run examples to see if library has been built successfully or not, because it anyway needs `TBB_DIR( TBBConfig.cmake)`.  
In this case how can i test libraries?

---

<div class="post-metadata">

### Author: ![imikejackson](https://discourse.itk.org/user_avatar/discourse.itk.org/imikejackson/32/35_2.png) [@imikejackson](https://discourse.itk.org/u/imikejackson)
#### Post date: [June 14, 2019, 6:29pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/17 "2019-06-14T18:29:43Z")

</div>

Can you run the prebuilt binaries from Intel? You can download them from Github. [https://github.com/intel/tbb/releases](https://github.com/intel/tbb/releases) The precompiled binaries work with all the compilers that ITK 5 supports so in general this should not be an issue. The only reason I can think of is that your internal IT policy forbids you to download precompiled binaries. Could you elaborate more on why you cannot use the precompiled binaries for TBB?

---

<div class="post-metadata">

### Author: ![dyollb](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/ac91a4/32.png) [@dyollb](https://discourse.itk.org/u/dyollb)
#### Post date: [June 21, 2019, 9:08pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/18 "2019-06-21T21:08:16Z")

</div>

The reason why, is that we are using a commercial thirdparty library which comes with tbb. To avoid conflicts, we build tbb ourselves, adding a prefix to the library names. The build process of TBB (for Windows), however, does not generate the appropriate TBBConfig.cmake file.

---

<div class="post-metadata">

### Author: ![dyollb](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/ac91a4/32.png) [@dyollb](https://discourse.itk.org/u/dyollb)
#### Post date: [June 21, 2019, 9:15pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/19 "2019-06-21T21:15:02Z")

</div>

If you build TBB on Windows it does not generate a TBBConfig.cmake.

We build TBB with a prefix for all libs, to avoid any conflict with TBB coming from a package we license from Spatial. This was the purpose of the patch, so I can manually specify the different library paths.

---

<div class="post-metadata">

### Author: ![Vladimir\_Fonov](https://discourse.itk.org/user_avatar/discourse.itk.org/vladimir_fonov/32/247_2.png) [@Vladimir\_Fonov](https://discourse.itk.org/u/Vladimir_Fonov)
#### Post date: [November 28, 2019, 5:31pm UTC](https://discourse.itk.org/t/itk-build-with-tbb/1954/20 "2019-11-28T17:31:33Z")

</div>

So, the solution on building TBB from the source code in a way to generate TBBConfig.cmake:

download and unpack tbb sources into ( I am using tbb\_2019 branch from ), then

MacOS:

```
cd <TBB directory>
make stdver=c++0x stdlib=libc++ tbb_build_prefix=lib
mkdir lib
cp build/lib_release/*.dylib lib
cmake -DTBB_ROOT=<TBB directory> -DTBB_OS=Darwin -DSAVE_TO=<TBB directory>/lib/ -P cmake/tbb_config_generator.cmake

```

Linux (64bit with gcc):

```
cd <TBB directory>
make stdver=c++0x tbb_build_prefix=lib
mkdir -p lib/intel64/gcc4.8/
cp build/lib_release/*.so.2 lib/intel64/gcc4.8/
cmake -DTBB_ROOT=<TBB directory> -DTBB_OS=Linux -DSAVE_TO=<TBB directory>/lib/ -P cmake/tbb_config_generator.cmake

```

Then TBB can be specified in ITK build as

```
-DTBB_DIR:PATH=<TBB directory>/lib
```

[Next page](https://discourse.itk.org/t/itk-build-with-tbb/1954.md?page=2)
