Skip to content

Conversation

Wangch29
Copy link

@Wangch29 Wangch29 commented Sep 11, 2025

Summary

On macOS, the build currently fails with:

ld: library 'atomic' not found

because CMake unconditionally adds -latomic when the builtin atomic probe fails.

However:

  • macOS libc++/Clang provides atomics without a separate libatomic
  • the system does not ship libatomic at all

What this patch does

This patch refines the detection logic:

  • Skip -latomic entirely on Apple platforms.
  • On non-Apple platforms, re-probe with -latomic using unsigned __int128
    (a more reliable trigger for architectures that actually need it).
  • As a fallback, use find_library(atomic) and only add -latomic if it exists.

This avoids build failures on macOS while preserving correct behavior on Linux
platforms where -latomic is truly required.

Reproduction (macOS 15.6.1, Apple clang 17.0.0)

rm -rf build && mkdir build && cd build
CC=clang CXX=clang++ cmake .. \
  -DCMAKE_BUILD_TYPE=Release \
  -DROCKSDB_BUILD_SHARED=ON \
  -DWITH_GFLAGS=ON -DWITH_SNAPPY=ON -DWITH_LZ4=ON \
  -DWITH_ZLIB=ON -DWITH_ZSTD=ON -DWITH_BZ2=ON
cmake --build . -j"$(sysctl -n hw.ncpu)"

Before this patch:

[ 92%] Built target rocksdb
[ 92%] Linking CXX shared library librocksdb.dylib
ld: library 'atomic' not found
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
gmake[2]: *** [CMakeFiles/rocksdb-shared.dir/build.make:5703: librocksdb.10.7.0.dylib] Error 1
gmake[1]: *** [CMakeFiles/Makefile2:201: CMakeFiles/rocksdb-shared.dir/all] Error 2
gmake: *** [Makefile:136: all] Error 2

After this patch:

[100%] Linking CXX executable db_bench
[100%] Built target db_bench
[100%] Linking CXX executable db_stress
[100%] Built target db_stress

@meta-cla meta-cla bot added the CLA Signed label Sep 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant