15

It's very strange behavior in my Clang compiler. I use Xcode (OS X), all is up-to-date. Why am I getting this warning in that simple code? If I remove those two lines the warning hides.

ld: warning: direct access in _main to global weak symbol std::__1::char_traits::eq(char, char) means the weak symbol cannot be overridden at runtime. This was likely caused by different translation units being compiled with different visibility settings.

int main( int argc, char* argv[] ) {
    std::string file = "test";
    size_t pos = file.find( "a" );
    return 0;
}
JavaRunner
  • 2,455
  • 5
  • 38
  • 52
  • 1
    Did you try to compile with `-fvisibility=hidden`? – sergej Apr 12 '16 at 08:10
  • 4
    @sergej Why should I hide this warning? I don't want to just ignore it. I want to find out what's wrong with my code and solve it without hiding it. – JavaRunner Apr 12 '16 at 09:27

1 Answers1

9

See Controlling Symbol Visibility @ developer.apple.com for details.

It looks like your libs (eg. the C++ standard library) and your code have been compiled with different visibility settings, at least, that is what the linker error message is saying.

To fix the warning, you should use the same visibility settings when compiling your code, eg -fvisibility=hidden.

sergej
  • 17,147
  • 6
  • 52
  • 89