Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined reference linking error #1332

Closed
pavel-cpp opened this issue Mar 21, 2024 · 6 comments
Closed

Undefined reference linking error #1332

pavel-cpp opened this issue Mar 21, 2024 · 6 comments
Assignees

Comments

@pavel-cpp
Copy link

Im using CMake with MinGW toolset. I decided to study your library, unfortunately, I encountered compilation errors and existing tickets on the Internet did not help fix the linking error.

My sources:

CMakeLists.txt
cmake_minimum_required(VERSION 3.28)
project(TBB_Learning)

set(CMAKE_CXX_STANDARD 17)

find_package(TBB REQUIRED)

if(TBB_FOUND)
    message(STATUS "TBB found")
endif ()

add_executable(TBB_Learning main.cpp)

target_link_libraries(TBB_Learning PRIVATE TBB::tbb)
main.cpp
#include <iostream>
#include <tbb/blocked_range.h>
#include <tbb/parallel_for.h>

using namespace tbb;

class Calculatator {
public:
    void operator()(const blocked_range<int> &r) const {
        for (int i = r.begin(); i < r.end(); ++i) {
            std::cout << i << std::endl;
        }
    }
};


int main(int argc, char *argv[]) {
    parallel_for(blocked_range<int>(0, 1000), Calculatator());

    return 0;
}
Logs
"C:\Users\green\AppData\Local\Programs\CLion Nova\bin\cmake\win\x64\bin\cmake.exe" --build E:\Development\CPP\CLionProjects\TBB_Learning\cmake-build-debug --target TBB_Learning -j 14
[1/2] Building CXX object CMakeFiles/TBB_Learning.dir/main.cpp.obj
[2/2] Linking CXX executable TBB_Learning.exe
FAILED: TBB_Learning.exe 
C:\Windows\system32\cmd.exe /C "cd . && C:\Users\green\AppData\Local\Programs\CLIONN~1\bin\mingw\bin\G__~1.EXE -g  CMakeFiles/TBB_Learning.dir/main.cpp.obj -o TBB_Learning.exe -Wl,--out-implib,libTBB_Learning.dll.a -Wl,--major-image-version,0,--minor-image-version,0  "C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/lib/tbb12_debug.lib"  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 && cd ."
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::wait_context::add_reference(long long)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_task.h:114: undefined reference to `tbb::detail::r1::notify_waiters(unsigned long long)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::execution_slot(tbb::detail::d1::execution_data const&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_task.h:169: undefined reference to `tbb::detail::r1::execution_slot(tbb::detail::d1::execution_data const*)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::spawn(tbb::detail::d1::task&, tbb::detail::d1::task_group_context&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_task.h:182: undefined reference to `tbb::detail::r1::spawn(tbb::detail::d1::task&, tbb::detail::d1::task_group_context&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::execute_and_wait(tbb::detail::d1::task&, tbb::detail::d1::task_group_context&, tbb::detail::d1::wait_context&, tbb::detail::d1::task_group_context&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_task.h:191: undefined reference to `tbb::detail::r1::execute_and_wait(tbb::detail::d1::task&, tbb::detail::d1::task_group_context&, tbb::detail::d1::wait_context&, tbb::detail::d1::task_group_context&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::task_group_context::task_group_context(tbb::detail::d1::task_group_context::context_traits, tbb::detail::d0::string_resource_index)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/task_group.h:268: undefined reference to `tbb::detail::r1::initialize(tbb::detail::d1::task_group_context&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::task_group_context::~task_group_context()':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/task_group.h:353: undefined reference to `tbb::detail::r1::destroy(tbb::detail::d1::task_group_context&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::task_group_context::is_group_execution_cancelled()':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/task_group.h:383: undefined reference to `tbb::detail::r1::is_group_execution_cancelled(tbb::detail::d1::task_group_context&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::current_thread_index()':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/task_arena.h:451: undefined reference to `tbb::detail::r1::execution_slot(tbb::detail::d1::execution_data const*)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::max_concurrency()':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/task_arena.h:463: undefined reference to `tbb::detail::r1::max_concurrency(tbb::detail::d1::task_arena_base const*)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>* tbb::detail::d1::small_object_allocator::new_object<tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>, tbb::detail::d1::blocked_range<int> const&, Calculatator const&, tbb::detail::d1::auto_partitioner const&, tbb::detail::d1::small_object_allocator&>(tbb::detail::d1::blocked_range<int> const&, Calculatator const&, tbb::detail::d1::auto_partitioner const&, tbb::detail::d1::small_object_allocator&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_small_object_pool.h:61: undefined reference to `tbb::detail::r1::allocate(tbb::detail::d1::small_object_pool*&, unsigned long long)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `void tbb::detail::d1::small_object_allocator::deallocate<tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const> >(tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>*, tbb::detail::d1::execution_data const&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_small_object_pool.h:90: undefined reference to `tbb::detail::r1::deallocate(tbb::detail::d1::small_object_pool&, void*, unsigned long long, tbb::detail::d1::execution_data const&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>* tbb::detail::d1::small_object_allocator::new_object<tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>, tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>&, tbb::detail::d0::split&, tbb::detail::d1::small_object_allocator&>(tbb::detail::d1::execution_data&, tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>&, tbb::detail::d0::split&, tbb::detail::d1::small_object_allocator&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_small_object_pool.h:53: undefined reference to `tbb::detail::r1::allocate(tbb::detail::d1::small_object_pool*&, unsigned long long, tbb::detail::d1::execution_data const&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::tree_node* tbb::detail::d1::small_object_allocator::new_object<tbb::detail::d1::tree_node, tbb::detail::d1::node*&, int, tbb::detail::d1::small_object_allocator&>(tbb::detail::d1::execution_data&, tbb::detail::d1::node*&, int&&, tbb::detail::d1::small_object_allocator&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_small_object_pool.h:53: undefined reference to `tbb::detail::r1::allocate(tbb::detail::d1::small_object_pool*&, unsigned long long, tbb::detail::d1::execution_data const&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `void tbb::detail::d1::small_object_allocator::deallocate<tbb::detail::d1::tree_node>(tbb::detail::d1::tree_node*, tbb::detail::d1::execution_data const&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_small_object_pool.h:90: undefined reference to `tbb::detail::r1::deallocate(tbb::detail::d1::small_object_pool&, void*, unsigned long long, tbb::detail::d1::execution_data const&)'
C:\Users\green\AppData\Local\Programs\CLion Nova\bin\mingw\bin/ld.exe: CMakeFiles/TBB_Learning.dir/main.cpp.obj: in function `tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>* tbb::detail::d1::small_object_allocator::new_object<tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>, tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>&, tbb::detail::d1::blocked_range<int> const&, unsigned char&, tbb::detail::d1::small_object_allocator&>(tbb::detail::d1::execution_data&, tbb::detail::d1::start_for<tbb::detail::d1::blocked_range<int>, Calculatator, tbb::detail::d1::auto_partitioner const>&, tbb::detail::d1::blocked_range<int> const&, unsigned char&, tbb::detail::d1::small_object_allocator&)':
C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/include/oneapi/tbb/detail/_small_object_pool.h:53: undefined reference to `tbb::detail::r1::allocate(tbb::detail::d1::small_object_pool*&, unsigned long long, tbb::detail::d1::execution_data const&)'
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
@sarathnandu
Copy link
Contributor

sarathnandu commented Mar 24, 2024

I think cmake is not able to find the path to the library here. One thing to try is to let CMake know where to search for TBBConfig directly,
Starting from oneTBB 2021.1, GitHub* release TBBConfig files in the binary packages are located under /lib/cmake/TBB
You can specify this as
cmake -DTBB_DIR=<TBB_ROOT>/lib/cmake/TBB ..

@isaevil
Copy link
Contributor

isaevil commented Mar 25, 2024

@sarathnandu @pavel-cpp CMake has found the library. In the log above there is link line: C:/Program Files (x86)/Intel/oneAPI/tbb/2021.11/lib/tbb12_debug.lib"
oneTBB library is a C++ library and built using MSVC so I am pretty sure it is not ABI compatible with MinGW. You should either rebuild oneTBB from source or not use MinGW toolchain in this case.

@pavel-cpp
Copy link
Author

When I studied the oneTBB source files, I noticed that there is an implementation for MinGW Toolchain, but it does not compile due to incorrect conversion of char to wchar_t.

@isaevil
Copy link
Contributor

isaevil commented Mar 31, 2024

You should be able to compile oneTBB from sources using MinGW. If you see any compile errors, please share error logs. Pull requests are welcome as well :)

@pavel-cpp
Copy link
Author

ok, i will try that on this week. You can try this too. Just try to fetch this by conan2.

@sarathnandu
Copy link
Contributor

I presume you were able to build oneTBB using MinGW. Closing this issue.
Feel free to open if you're facing any trouble.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants