Open josch opened 3 months ago
Thank you for reporting this.
Have you considered using the CMAKE_EXE_LINKER_FLAGS
option, e.g.,
cmake -DCMAKE_EXE_LINKER_FLAGS="-Wl,--push-state,--no-as-needed,-latomic,--pop-state" .
But that does not resolve the issue. It hides it.
Would a real solution not involve changing the TBBTargets.cmake
such that it automatically adds the correct linker flags via the TBB::tbb
interface properties?
Hi @josch,
Sorry for the delayed response.
We already have an open pull request to address this issue: #987
Could you please see if it resolves it for you? If so, we could complete and merge the patch, once all the comments are addressed. Please fell free to contribute.
Sorry for the delayed response.
No worries! I assume you are also just a volunteer doing this in your free time -- I know the problem. Thank you for getting back to me! :slightly_smiling_face:
We already have an open pull request to address this issue: https://github.com/oneapi-src/oneTBB/pull/987
The changes from that PR do not solve this issue. I patched the onetbb Debian package with the patch by @glaubitz and then compiled vcmi (the package where I observed the issue) with it. I'm getting the same error. I also tried my minimal reproducer from above without success.
I think (with my limited cmake knowledge) that the reason why it does not work is, that the atomic library gets added to TBB_COMMON_LINK_LIBS
and those are used in src/tbb/CMakeLists.txt
but with target_link_libraries(tbb PRIVATE ...
. The PRIVATE
prevents the atomic library to get propagated to programs linked against tbb.
With that explanation in mind I tried out building tbb with the following patch:
--- a/src/tbb/CMakeLists.txt
+++ b/src/tbb/CMakeLists.txt
@@ -124,6 +124,8 @@ target_link_libraries(tbb
Threads::Threads
${TBB_LIB_LINK_LIBS}
${TBB_COMMON_LINK_LIBS}
+ PUBLIC
+ atomic
)
tbb_install_target(tbb)
And with that I can compile my minimal reproducer and I get this:
$ make VERBOSE=1
[...]
[100%] Linking CXX executable //hello
/usr/bin/cmake -E cmake_link_script //CMakeFiles/hello.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/hello.dir/hello.cc.o -o //hello usr/lib/arm-linux-gnueabi/libtbb.so.12.12 -latomic
As you can see, by adding atomic to PUBLIC
, cmake projects that link against tbb will also link against atomic and this will make the build succeed. So maybe the patch from #987 could be adjusted to add atomic to PUBLIC
link libraries instead of to the PRIVATE
ones?
But that does not resolve the issue. It hides it.
Just pointing out that even this is hiding the issue. The real issue seems to be in gcc: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81358
Summary
On armel, compiling cmake projects using onetbb fails because of missing
-latomic
. We worked around this in Debian using CMake snippets like this:One instance of this problem is vcmi: https://github.com/vcmi/vcmi/issues/3109
The "armel" architecture is the only platform exhibiting that problem amongst the ones that we build vcmi for in Debian. Other platforms like armhf, arm64, mips, powerpc, riscv, s390x etc do not have this problem and build just fine.
I talked with the Debian porters for the ARM platform and was told that the problem should only happen on platforms without native atomics, so maybe the problem also happens on parisc or sh.
Version
2021.12.0-1
Environment
Observed Behavior
Compiling a test executable on armel yielded an "undefined reference to symbol" error.
Expected Behavior
Successful compilation like on all the other architectures.
Steps To Reproduce
CMakeLists.txt:
hello.cc
Compile it: