-
-
Notifications
You must be signed in to change notification settings - Fork 123
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
atomics detection is broken #141
Comments
Once
|
The code below from CMakeLists.txt seems to be broken using the latest OSes, compilers, ...
Ideally we would like to replace the code above and use a proper CMake module for libatomic. This did not exist a few years ago, but according to ChatGPT we could now potentially use: # If atomic 64-bit code fails to compile then we
# need to add libatomic to the linker flags.
if(NOT atomic64)
find_package(LibAtomic REQUIRED)
set(LIBATOMIC ${LibAtomic_LIBRARIES})
message(STATUS "Found libatomic: ${LIBATOMIC}")
endif() instead of: if(NOT atomic64)
find_library(ATOMIC NAMES atomic libatomic.so.1)
if(ATOMIC)
set(LIBATOMIC ${ATOMIC})
message(STATUS "Found libatomic: ${LIBATOMIC}")
else()
check_cxx_source_compiles("
#include <atomic>
#include <stdint.h>
int main() {
std::atomic<int32_t> x;
x = 1;
x--;
return (int) x;
}"
atomic32)
if(atomic32)
message(FATAL_ERROR "Failed to find libatomic!")
endif()
endif()
endif() I have not tested this yet, if it works there is a high risk that it will only work on newer OSes. |
I am pretty sure extension should not be added to a library name in the check. Also on Mac is will be |
Another option that would likely fix the problem and work well on old OSes is: if(NOT atomic64)
find_library(ATOMIC NAMES atomic libatomic.so.1)
if(ATOMIC)
set(LIBATOMIC ${ATOMIC})
message(STATUS "Found libatomic: ${LIBATOMIC}")
else()
# Try -latomic as a fallback if our code fails to detect libatomic
set(LIBATOMIC atomic)
message(STATUS "Found libatomic: ${LIBATOMIC}")
endif()
endif() |
@kimwalisch Something like this should work: pghysels/STRUMPACK@be6d1f6 See also: https://github.com/grpc/grpc/pull/21341/files P. S. I should open an issue with CMake upstream, this has to be really implemented with CMake to begin with. |
@barracuda156 Can you please let me know where libatomic is located on your PC and how it is named? I have found another code snippet online that I think is superior to the solutions I have seen so far: https://github.com/agroal/pgagroal/blob/master/cmake/FindLibatomic.cmake#L6. It is similar to the code used in primesieve but it includes hints to a list of paths where libatomic cloud potentially be located if the compiler/linker cannot find it in the default path. |
@barracuda156 Could you please try if the following fix works on your PC? Add
instead of:
In the |
I was able to partially reproduce your issue on macOS 14.2 with homebrew GCC 13.2. I tried all of the potential solutions discussed in this thread, in the end the only solution that worked was adding -latomic to the linker options. So I have added this method as a fallback (https://github.com/kimwalisch/primesieve/blob/master/cmake/libatomic.cmake#L39) in case our other methods fail to find libatomic. Could you please try if the latest code from the master branch works fine on your PC? |
@kimwalisch Sorry, it was a busy day, I am off the machine now. I can verify tomorrow, but passing |
Closing, I assume I have fixed this. |
This is GCC, so obviously
libatomic
is there. The check is not looking for it at all however:Of course it will not work without passing
-latomic
flag.The text was updated successfully, but these errors were encountered: