Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
299 views
in Technique[技术] by (71.8m points)

c++ - -x link flag causing link errors on Mac OSX 10.9 (bug?)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...