Hi, I have figured out what the problem is:
LLVM/Clang with OpenMP requires linking against libatomic only when using 128-bit integers. The following program fails to compile using Clang-6.0 on Ubuntu 18 x86_64 using: $ clang++ -fopenmp=libomp test.cpp #include <omp.h> int main() { __int128_t sum = 0; #pragma omp parallel for reduction(+: sum) for (int i = 0; i < 100; i++) sum += i; return 0; } But it compiles fine when adding -latomic: clang++ -fopenmp=libomp test.cpp -latomic For me, this is neither a CMake bug nor an LLVM/Clang bug but it is still very confusing as GCC does not require linking against libatomic. Regards, Kim On Fri, May 4, 2018 at 7:48 PM, Kim Walisch <kim.wali...@gmail.com> wrote: > Hi, > > The latest Clang-6.0 compiler finally enables OpenMP by default on > Linux (e.g. Ubuntu-18 x86_64). > > But OpenMP programs using Clang-6.0/CMake-3.10 fail to compile: > > [100%] Linking CXX executable primecount > libprimecount.a(P2.cpp.o): In function `.omp_outlined..7': > P2.cpp:(.text+0x2194): undefined reference to `__atomic_load' > P2.cpp:(.text+0x21ef): undefined reference to `__atomic_compare_exchange' > CMakeFiles/primecount.dir/build.make:148: recipe for target 'primecount' > failed > make[2]: *** [primecount] Error 1 > > The problem is that: > > target_link_libraries(myprogram OpenMP::OpenMP_CXX) > > does not add libatomic to the linker options which LLVM/Clang's OpenMP > library depends upon. When I manually add -latomic to the linker > options my OpenMP programs compile & link fine using Clang-6.0/CMake-3.10. > > Regards, > Kim >
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake