Created attachment 30026 [details] Preprocessed input files Output of gcc -v: Thread model: posix gcc version 4.8.0 (GCC) Target: x86_64-unknown-linux-gnu Input file test.cpp: #include <random> extern thread_local std::default_random_engine rng; int main() { return rng(); } Input file test2.cpp: #include <random> thread_local std::default_random_engine rng; Command line and output: g++ -std=c++11 -c test.cpp && g++ -std=c++11 -c test2.cpp && g++ -std=c++11 test.o test2.o test.o:test.cpp:function _ZTW3rng: error: undefined reference to '_ZTH3rng' collect2: error: ld returned 1 exit status Complete preprocessed output attached. I can't reproduce this with a single translation unit.
In any case the actual std::default_random_engine doesn't play any special role: the same error happens including, as test.h, something like namespace std { struct default_random_engine { default_random_engine() { } int operator()() { return 1; } }; }
Confirmed for gcc 4.8.1.
Please have a look at bug #55800 .
Confirmed for gcc 4.8.2
Works with 4.9 for me.