htool icon indicating copy to clipboard operation
htool copied to clipboard

[joss-review] Building in debug mode causes linker errors for `tbb`

Open nilsfriess opened this issue 2 months ago • 7 comments

To reproduce:

mkdir build
cd build
cmake .. -DHTOOL_WITH_EXAMPLES=True -DCMAKE_BUILD_TYPE=Debug
make Use_hmatrix

When I don't specify -DCMAKE_BUILD_TYPE=Debug or explicitly use -DCMAKE_BUILD_TYPE=Release, everything works. In debug mode, the linker complains that it cannot find some tbb::detail::bla bla functions.

This fixes it:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 63d568d..042388c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -109,7 +109,7 @@ find_package(HPDDM)
 #=== HTOOL as header only library
 add_library(htool INTERFACE)
 target_include_directories(htool INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include> ${HPDDM_INCLUDE_DIRS} ${MKL_INC_DIR})
-target_link_libraries(htool INTERFACE MPI::MPI_CXX BLAS::BLAS LAPACK::LAPACK)
+target_link_libraries(htool INTERFACE MPI::MPI_CXX BLAS::BLAS LAPACK::LAPACK tbb)
 if(OpenMP_CXX_FOUND)
     target_link_libraries(htool INTERFACE OpenMP::OpenMP_CXX)
 endif()

but I have no idea why this is not necessary in Release mode.

cc: https://github.com/openjournals/joss-reviews/issues/9279

nilsfriess avatar Nov 10 '25 13:11 nilsfriess

Could share the full log and give more details on your environment (OS, compiler, etc.) ?

The CI tests for (Debian x Ubuntu) x (gcc x clang) x (OpenMPI x MPICH) in Debug mode, so it is a little bit surprising.

PierreMarchand20 avatar Nov 10 '25 13:11 PierreMarchand20

I've been able to reproduce the issue, let me sort this out with @PierreMarchand20, thanks for the report.

prj- avatar Nov 10 '25 13:11 prj-

I am on Ubuntu 24.04 using gcc 13.3. An answer on stackoverflow suggested to remove the libtbb-dev package and that indeed fixed the issue. No idea what's going on, but it's certainly not a htool problem.

Edit: @prj- I saw your comment too late and already closed the issue (and apparently I don't have permission to reopen).

nilsfriess avatar Nov 10 '25 14:11 nilsfriess

In the meantime, you should be able to bypass the issue by setting -DCMAKE_CXX_COMPILER=mpiicpx (or whatever flag to force the use of Intel compiler instead of g++).

prj- avatar Nov 10 '25 14:11 prj-

We need to sort this out, I've the same issue on a machine where I don't have root privileges, so it's not as easy as removing the faulty package. But yeah, not really an Htool issue per say.

prj- avatar Nov 10 '25 14:11 prj-

@nilsfriess We fixed the issue with the reproducer of @prj- in #70.

But in the reproducer, the issue came from using MKL, so that TBB was in the include path (because of the setvars.h when using oneapi), and for some reasons, the compiler then tries to use TBB that it cannot find when linking. So we added TBB link flag when using MKL. I am not 100% sure it solves the issue you encountered though. Could you try with #70 if it works for you?

PierreMarchand20 avatar Nov 10 '25 15:11 PierreMarchand20

Could you try with https://github.com/htool-ddm/htool/pull/70 if it works for you?

You'll have to reinstall the faulty package first.

prj- avatar Nov 10 '25 15:11 prj-

This is fixed in #70. Do not hesitate to reopen if there is still an issue with TBB.

PierreMarchand20 avatar Nov 28 '25 14:11 PierreMarchand20