chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes

Summary: isolator++ is not compatible with gcc "-static-libstdc++" linker flag.

Steps to reproduce:

  • Isolator++ version: 4.1.0
  • OS: CentOS or ubuntu
  1. Install typemock
  2. add linker flag to makefile at line 168 of \\\"/usr/share/typemock/Examples/Isolator++.Examples.GCC/MakeFile\\\" 
ifndef MAKEDEPS

 echo Linking $@: $(LD) $(LD_FLAGS) $^ -o $(@) $(LIBS)

 $(LD) $(LD_FLAGS) $^ -o $(@) $(LIBS) -pthread -lrt -ldl  -Wl,-rpath=$(ISOLATOR_LIBDIR) -static-libstdc++  # new flag here 
endi

run  `make clean && make `,  you will get error 'undefined reference to `std::hash<std::string>::operator()(std::string) const`

Reason:

When you use `std::hash<std::string>::operator()(std::string) const`, it will ends up as an weak but defined symbol in your object file:

$ cat test.cpp
#include <string>
#include <functional>
int main() {
std::string a = "123";
const std::hash<std::string> string_hash{};
std::hash<std::string> const &string_hash_ref = string_hash;
std::size_t str_hash_2 = string_hash_ref(a);
return 0;
}

$ g++ test.cpp -std=c++11

$ readelf -s a.out|c++filt|grep std|grep operator|grep string
    72: 0000000000400a18    67 FUNC    WEAK   DEFAULT   12 std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) const

Unless if it is compiled by some kind of old gcc with std gnu++0x, you may get an undefined symbol in your object file.

Isolator++ seems match in this case:

readelf -s libisolator.a|c++filt|grep std|grep operator|grep string
   405: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const
   420: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT  UND std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >::operator()(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const

According to the libstdc++ source code, the `std::hash<std::string>::operator()(std::string) const` impl is only supported in the dynamic linked version because of Macro _GLIBCXX_SHARED, see the source code at the reference section.

Reference:

Macro _GLIBCXX_SHARED https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B11/compatibility-c%2B%2B0x.cc#L43

std::hash<std::string>::operator()(std::string) const impl https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B11/compatibility-c%2B%2B0x.cc#L75

asked by zhao (600 points)

1 Answer

0 votes
Hey Zhao,

Thank you for the detailed request.

 Can you please open a ticket? send all of the information above to support@typemock.com

Thank you for your cooperation.
answered by CoralTypemock (940 points)
...