Cling and intel TBB?

Hi there,
I successfully compiled Cling on windows (VS 2017) and am just starting to play with it, I must say I’m starting to love it!
Now I would like to also use TBB in my project, so I created a simple app, in which I link tbb.lib.
The problem is as soon as I add the include (in my case #include “tbb\flow_graph.h”), I getting this error:

In file included from input_line_3:1:
In file included from C:\ThirdPartyLibs\tbb2018_20170919oss\include\tbb\flow_graph.h:24:
In file included from C:\ThirdPartyLibs\tbb2018_20170919oss\include\tbb/tbb_stddef.h:123:
C:\ThirdPartyLibs\tbb2018_20170919oss\include\tbb/internal/_tbb_windef.h:32:2: error: TBB requires linkage with multithreaded C/C++ runtime library. Choose multithreaded DLL runtime in project settings, or
use /MD[d] compiler switch.
#error TBB requires linkage with multithreaded C/C++ runtime library. \

Of course my app is compiled with the /MD flag.

Any help will be appreciated!

Hi there. Did you compile cling with /MD?

Hi, yes I did, So I tried 2 things, the first one was to load the tbb. lib +the headers in cling.exe,
then to create my own app with an interpreter and tbb.lib linked to that app:

#include "tbb\flow_graph.h"
#include "cling/Interpreter/Interpreter.h"
#include "cling/MetaProcessor/MetaProcessor.h"
#include "cling/UserInterface/UserInterface.h"

#include "clang/Basic/LangOptions.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/FrontendTool/Utils.h"

#include "llvm/Support/Signals.h"
#include "llvm/Support/PrettyStackTrace.h"
#include "llvm/Support/ManagedStatic.h"

#include <stdarg.h>
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>

#if defined(WIN32) && defined(_MSC_VER)
#include <crtdbg.h>
int main(int argc, const char* const* argv)
    cling::Interpreter interp(argc, argv, LLVMRESDIR);
    interp.process("#include \"tbb\\flow_graph.h\"");
    return 0;

Both compiled with /MD, but none worked

Cling does not full support of Windows. That said, it looks like that’s the failing code

#if !defined(_MT)
#error TBB requires linkage with multithreaded C/C++ runtime library. \
       Choose multithreaded DLL runtime in project settings, or use /MD[d] compiler switch.

This means that cling is not defining _MT in its runtime even though it was built with /MD. To implement the semantics of MD might be tricky we need also to load msvcrt according to documentation.

You could try two things. First try starting cling /MD and see if the runtime will define _MT. If that does not work you could force it to be defined in a similar to that manner.

Thanks Vassil,

interp.process("#define _MT");

allowed me to include TBB!!!
now I’m facing another problem, using a tbb for loop like this:

tbb::parallel_for(size_t(0), size_t(5), [=](size_t i) {
          printf("i is %d", int(i));

is giving this error:

LLVM ERROR: ELF COMDATs only support SelectionKind::Any, ‘??_7task@tbb@@6B@’ cannot be lowered.

and this flow graph example is crashing:

#include "tbb/flow_graph.h"
#include <iostream>

using namespace std;
using namespace tbb::flow;

int main() {
    graph g;
    continue_node< continue_msg> hello( g,
      []( const continue_msg &) {
          cout << "Hello";
    continue_node< continue_msg> world( g,
      []( const continue_msg &) {
          cout << " World\n";
    make_edge(hello, world);
    return 0;

I think you are hitting this, unrelated to tbb, issue: Exception when using virtual functions (on windows)

Hi Vassil,
So as TBB is already a compiled lib, it seems this is a dead end for now right?
I’ll try to stick with openMP then.

Thanks anyway :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.