I am facing a weird linker issue with clang++ - it is able to find the definition of std::string class but not of std::ios_base::failure class.
$ cat foo.cpp
#include <string>
#include <iostream>
int main()
{
std::string msg = "hello world";
std::ios_base::failure f(msg);
std::cout << msg << std::endl;
return 0;
}
$ clang++ foo.cpp
/tmp/foo-b77625.o: In function `main':
foo.cpp:(.text+0x4d): undefined reference to `std::ios_base::failure::failure(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'
clang-3.7: error: linker command failed with exit code 1 (use -v to see invocation)
$ clang++ --version
clang version 3.7.0 (trunk 239466)
Target: x86_64-unknown-linux-gnu
Thread model: posix
I noticed that if I comment the instantiation of std::ios_base::failure, the program links (and executes) correctly.
$ clang++ foo.cpp && ./a.out
hello world
Can someone please help me understand this behavior and how to fix it?
P.S. I observed the same behavior with clang version 3.6.0 as well.