0

I am trying to use std::atomic<> with struct sigaction in std::vector but my test case fails with linker error in both Clang and GCC. Why is that? I all types were supported, even non-fundamental ones.

#include <atomic>
#include <vector>
#include <signal.h>

std::vector<std::atomic<struct sigaction> > vec (1);

int main() {
    struct sigaction sa = { };
    vec[0].store (sa);
    sa = vec[0].load ();
    return 0;
}

See http://coliru.stacked-crooked.com/a/df4cfcbe48ecc992. The result is

g++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out ; g++ -v 2>&1 |grep 'gcc version'
clang++ -std=c++11 -O2 -Wall -pedantic -pthread main.cpp && ./a.out ; clang++ -v 2>&1 |grep 'clang version'  
/tmp/ccgNkprP.o: In function `main':
main.cpp:(.text.startup+0x41): undefined reference to `__atomic_store'
main.cpp:(.text.startup+0x5f): undefined reference to `__atomic_load'
collect2: error: ld returned 1 exit status
gcc version 5.2.0 (GCC)
/tmp/main-c75098.o: In function `main':
main.cpp:(.text+0x96): undefined reference to `__atomic_store'
main.cpp:(.text+0xb1): undefined reference to `__atomic_load'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
clang version 3.6.0 (tags/RELEASE_360/final 235480)
dyp
  • 38,334
  • 13
  • 112
  • 177
wilx
  • 17,697
  • 6
  • 59
  • 114

0 Answers0