C++11 铿锵++;macosxc++;11链接器问题

C++11 铿锵++;macosxc++;11链接器问题,c++11,undefined,symbols,clang++,C++11,Undefined,Symbols,Clang++,我在使用xcode 4.6.2中的clang++在mac os x 10.8.3下使用“-std=c++11-stdlib=libc++”编译程序时遇到问题 当我尝试使用std::mem\u fn()或(不推荐使用)std::mem\u fun\u ref()时,我得到链接器错误“找不到符号”。同样的代码(使用std::mem_fun_ref而不是std::mem_fn)编译和链接在c++03标准下没有任何问题 如果我在一个对象上调用同一个成员函数,而没有通过mem_fn或mem_fun_ref

我在使用xcode 4.6.2中的clang++在mac os x 10.8.3下使用“-std=c++11-stdlib=libc++”编译程序时遇到问题

当我尝试使用std::mem\u fn()或(不推荐使用)std::mem\u fun\u ref()时,我得到链接器错误“找不到符号”。同样的代码(使用std::mem_fun_ref而不是std::mem_fn)编译和链接在c++03标准下没有任何问题

如果我在一个对象上调用同一个成员函数,而没有通过mem_fn或mem_fun_ref引用它,那么程序编译和运行不会出现任何问题。这是一个叮当作响的问题,一个苹果操作系统的问题,还是我做错了什么

守则:

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(int argc, char **arvc)
{

  /* The beginning of the function compiles without any errors */

  string str = "It's a test)";
  if (str.empty())
  {
    cout << "String is empty!!!" << endl;
  }
  vector<string> v1;
  v1.push_back("str1");
  v1.push_back("str2");
  v1.push_back("");
  v1.push_back("str4");
  v1.push_back("");
  v1.push_back("str6");

  /* The code after this point leads to linker error  */

  vector<string>::iterator it = remove_if(v1.begin(), v1.end(), mem_fn(&string::empty));
  v1.erase(it, v1.end());
  for (it = v1.begin(); it < v1.end(); ++it)
  {
    cout << "   '" << *it << "'" << endl;
  }

  return 0;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main(int argc,字符**arvc)
{
/*函数的开头编译时没有任何错误*/
string str=“这是一个测试)”;
if(str.empty())
{

cout这是一个叮当作响的bug。但是我找不到关于它的bug报告。如果有bug报告,我将不胜感激

问题是
string::empty
标记为“始终在线”,但
string
模板也标记为extern,这意味着它已经为您实例化了

出于某种原因,当我们有了这个组合,并且您形成了一个指向always_内联成员的成员函数指针时,clang拒绝对其进行概述,以便它可以指向它。只有当实例化被标记为extern时,它才会拒绝

如果禁用extern或always_inline,则代码将正常工作。您可以通过将其包含在“C++其他标志”中来禁用前者:


谢谢你的回复!这很有帮助!)不幸的是,我的英语太差了,无法正确地写错误报告。所以如果你能做到的话,那就太好了:)
$ xcrun clang++ -v -std=c++11 -stdlib=libc++ ../src/test_cxx.cpp
Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)
Target: x86_64-apple-darwin12.3.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.8.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test_cxx.cpp -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 136 -v -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.2 -isysroot / -fmodule-cache-path /var/folders/nz/0x05d6p14gddzxxn8ymnn74c0000gn/T/clang-module-cache -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Volumes/Work/projects/web/sp3/build -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.8.0 -fobjc-dispatch-method=mixed -fobjc-default-synthesize-properties -fcxx-exceptions -fexceptions -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/nz/0x05d6p14gddzxxn8ymnn74c0000gn/T/test_cxx-kAQ3wk.o -x c++ ../src/test_cxx.cpp
clang -cc1 version 4.2 based upon LLVM 3.2svn default target x86_64-apple-darwin12.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.2/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.8.0 -syslibroot / -o a.out /var/folders/nz/0x05d6p14gddzxxn8ymnn74c0000gn/T/test_cxx-kAQ3wk.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/4.2/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::empty() const", referenced from:
      _main in test_cxx-kAQ3wk.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
-D'_LIBCPP_EXTERN_TEMPLATE(...)='