Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get "ld: warning: direct access in _main to global weak symbol" in this simple code? [duplicate]

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;
}
like image 506
JavaRunner Avatar asked Apr 12 '16 08:04

JavaRunner


1 Answers

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.

like image 159
sergej Avatar answered Oct 02 '22 03:10

sergej