Clang ++: atomic, not compiling

// http://en.cppreference.com/w/cpp/atomic/atomic/is_lock_free

#include <iostream>
#include <utility>
#include <atomic>

struct A { int a[100]; };
struct B { int x, y; };
int main()
{
    std::cout << std::boolalpha
              << "std::atomic<A> is lock free? "
              << std::atomic<A>{}.is_lock_free() << '\n'
              << "std::atomic<B> is lock free? "
              << std::atomic<B>{}.is_lock_free() << '\n';
}

Which magic compiler or linker flag need to be added to solve this problem?

$ clang++ --version
Apple LLVM version 10.0.0 (clang-1000.10.44.4)
Target: x86_64-apple-darwin18.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

$ clang++ -o atomic atomic.cpp -std=c++14 -O2 -Wall -pedantic -lpthread
Undefined symbols for architecture x86_64:
  "___atomic_is_lock_free", referenced from:
     _main in atomic-e3a97a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Edit (2019.01.16): even -latomic doesn't work

$ make atomic
$ clang++ -o atomic atomic.cpp -std=c++14 -O2 -Wall -pedantic -lpthread -latomic
ld: library not found for -latomic
clang: error: linker command failed with exit code 1 (use -v to see invocation)
+5
source share

Source: https://habr.com/ru/post/1670353/


All Articles