Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2421 Discussions

undefined reference to ....tbb compilation error

luca_d_
Beginner
1,725 Views

THIS IS THE CODE (i use clion.... and cmake)

 

#include "tbb/parallel_for.h"
#include "tbb/task_scheduler_init.h"
#include <iostream>
#include <vector>

struct mytask {
    mytask(size_t n)
            :_n(n)
    {}
    void operator()() {
        for (int i=0;i<1000000;++i) {}  // Deliberately run slow
        std::cerr << "[" << _n << "]";
    }
    size_t _n;
};

int main(int,char**) {

    //tbb::task_scheduler_init init;  // Automatic number of threads
    tbb::task_scheduler_init init(tbb::task_scheduler_init::default_num_threads());  // Explicit number of threads

    std::vector<mytask> tasks;
    for (int i=0;i<1000;++i)
        tasks.push_back(mytask(i));

    tbb::parallel_for(
            tbb::blocked_range<size_t>(0,tasks.size()),
            [&tasks](const tbb::blocked_range<size_t>& r) {
                for (size_t i=r.begin();i<r.end();++i) tasks();
            }
    );

    std::cerr << std::endl;

    return 0;
}

 

the error is :

CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "main":
/home/luca/CLionProjects/fibonacci_parallelo/main.cpp:20: riferimento non definito a "tbb::task_scheduler_init::default_num_threads()"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "tbb::interface9::internal::start_for<tbb::blocked_range<unsigned long>, main::{lambda(tbb::blocked_range<unsigned long> const&)#1}, tbb::auto_partitioner const>::run(tbb::blocked_range<unsigned long> const&, {lambda(tbb::blocked_range<unsigned long> const&)#1} const&, tbb::auto_partitioner&)":
/home/luca/tbb-2017_U7/include/tbb/parallel_for.h:87: riferimento non definito a "tbb::task_group_context::~task_group_context()"
/home/luca/tbb-2017_U7/include/tbb/parallel_for.h:87: riferimento non definito a "tbb::task_group_context::~task_group_context()"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o:(.rodata+0xf8): riferimento non definito a "typeinfo for tbb::task"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "tbb::task_group_context::task_group_context(tbb::task_group_context::kind_type, unsigned long)":
/home/luca/tbb-2017_U7/include/tbb/task.h:463: riferimento non definito a "tbb::task_group_context::init()"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "tbb::task::task()":
/home/luca/tbb-2017_U7/include/tbb/task.h:569: riferimento non definito a "vtable for tbb::task"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "tbb::task::~task()":
/home/luca/tbb-2017_U7/include/tbb/task.h:573: riferimento non definito a "vtable for tbb::task"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "tbb::task::is_cancelled() const":
/home/luca/tbb-2017_U7/include/tbb/task.h:875: riferimento non definito a "tbb::task_group_context::is_group_execution_cancelled() const"
CMakeFiles/fibonacci_parallelo.dir/main.cpp.o: nella funzione "operator new(unsigned long, tbb::internal::allocate_root_with_context_proxy const&)":
/home/luca/tbb-2017_U7/include/tbb/task.h:1018: riferimento non definito a "tbb::internal::allocate_root_with_context_proxy::allocate(unsigned long) const"

*and other more*

 

 

for every function in tbb::task there is "a unspecified reference to...."

0 Kudos
1 Reply
Alexei_K_Intel
Employee
1,725 Views

Hi,

Do you link Intel TBB library to the application? E.g. "-ltbb" with gcc and some other compilers.

Regards,
Alex

Reply