【发布时间】:2013-10-29 17:01:24
【问题描述】:
我定义了一个操纵器:
inline std::ostream& my_manip(std::ostream& os);
我是这样使用的:
std::cout << my_manip << ...;
在调试和发布模式下使用 Boost.bjam 编译所有这些都很好。但是,当需要链接时,我仅在发布模式下收到以下错误:
Undefined symbols for architecture x86_64:
"std::__1::basic_ostream<char, std::__1::char_traits<char> >::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >& (*)(std::__1::basic_ostream<char, std::__1::char_traits<char> >&))", referenced from:
my_routine in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
或者,更清晰:
Undefined symbols for architecture x86_64:
"std::ostream::operator<<(std::ostream& (*)(std::ostream&))", referenced from:
my_routine in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
如果我注释掉操纵器,一切都可以在调试和发布模式下编译和链接。
如果我留在操纵器中,我可以通过使用 -O0 重建项目来解决链接器错误,但是如果我的发布模式是 bjam 默认值 (-O3),我会更喜欢它。
我正在运行 Xcode 4.6.2 及其相关的 clang:
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
如何让这个操纵器正确链接优化?
【问题讨论】:
-
似乎很多人在更新到 Mavericks 后开始出现链接器错误... 这个 SO 帖子有帮助吗:?stackoverflow.com/questions/19550436/…
-
@AndyG:感谢您的链接,不幸的是它似乎无关。与
-O0编译的源链接不会产生错误,因此我能够获得 something 进行链接。而且我还在运行 10.8.5 和 Xcode 4.6.2。
标签: c++11 clang linker-errors bjam iomanip