According to ld man pages, the -x link flag suppresses putting non-global symbols into the output file's symbol table. These symbols are useful for debugging but are not used at runtime. But this flag is causing link errors for me on Mavericks. For example, the following source file:
struct Yo
{
Yo() {}
};
void useYo()
{
Yo yo;
}
Compiled/linked as follows:
c++ -arch x86_64 -bundle -Wl,-x -o tc.so tc.cpp
Produces the following output:
ld: internal error: atom not found in symbolIndex(__ZN2YoC1Ev) for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The constructor Yo::Yo() is the problem:
c++filt __ZN2YoC1Ev
Yo::Yo()
Removing the -x link flag fixes the problem. Moving the constructor implementation outside the structure declaration also fixes the problem. This code compile/links fine:
struct Yo
{
Yo();
};
Yo::Yo() {}
void useYo()
{
Yo yo;
}
Here's my compiler info:
Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.3.0
Thread model: posix
Is this a bug in clang or the linker, or is there some reason I should not be using the -x link flag?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…