Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ std::string::empty的未定义符号错误;c++;Mac OS High Sierra上的标准方法链接错误_C++_Macos_Boost_Clang_Linker Errors - Fatal编程技术网

C++ std::string::empty的未定义符号错误;c++;Mac OS High Sierra上的标准方法链接错误

C++ std::string::empty的未定义符号错误;c++;Mac OS High Sierra上的标准方法链接错误,c++,macos,boost,clang,linker-errors,C++,Macos,Boost,Clang,Linker Errors,我只是想编译下面的示例cpp文件; 我如何解决这个问题?请帮忙 p、 美国。 我在网上发现了同样的问题,但没有答案。 #包括 #包括 #包括 int main(){ std::vector str_值={“abc”,“bde”}; auto count2=std::count\u if(str\u values.begin(),str\u values.end(), std::mem_fn(&std::string::empty)); (b)第2项; 返回0; } 它显示了同样的错误 架构

我只是想编译下面的示例cpp文件;

我如何解决这个问题?请帮忙

p、 美国。 我在网上发现了同样的问题,但没有答案。

#包括
#包括
#包括
int main(){
std::vector str_值={“abc”,“bde”};
auto count2=std::count\u if(str\u values.begin(),str\u values.end(),
std::mem_fn(&std::string::empty));
(b)第2项;
返回0;
}
它显示了同样的错误

架构x86_64的未定义符号: “std::uu 1::基本字符串,std::u 1::分配器>::empty()const”,引用自: _主要在boost_practice.cpp.o ld:找不到架构x86_64的符号

我已经找到了rttr的标准_types.cpp源文件中所述的答案

// explicit instantiation of std::string needed, otherwise we get a linker error with clang on osx
// thats a bug in libc++, because of interaction with __attribute__ ((__visibility__("hidden"), __always_inline__)) in std::string
template class std::basic_string<char>;
//需要std::string的显式实例化,否则在osx上会出现链接器错误
//这是libc++中的一个错误,因为它与std::string中的uuu属性uuu((uuu可见性uuu(“隐藏”),uu始终u内联uuu))交互
模板类std::basic_字符串;

首先,简化。制作一个只创建std::string并对其调用empty()的测试程序。没有推进。它的构建和运行是否正确?是的。没问题。现在通过获取和存储odr的地址,创建一个odr使用的
std::string::empty
。我不知道odr是什么,发现它是一个定义规则。但我还是不能理解你的意思,我从这里理解了odr的意思。
c++ -I/usr/local/opt/boost/include --std=c++14 boost_practice.cpp
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::empty() const", referenced from:
      sample2() in boost_practice-bc38e6.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
c++ -v -stdlib=libc++ -I/usr/local/opt/boost/include --std=c++11 boost_practice.cpp
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name boost_practice.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -I /usr/local/opt/boost/include -stdlib=libc++ --std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/eugene/project/private/cpp_practice/src -ferror-limit 19 -fmessage-length 100 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/_9/fqnfrxq56sj6gg95cc6nk1100000gn/T/boost_practice-bc871d.o -x c++ boost_practice.cpp
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.3.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/opt/boost/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/include
 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/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 -lto_library /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.13.0 -o a.out /var/folders/_9/fqnfrxq56sj6gg95cc6nk1100000gn/T/boost_practice-bc871d.o -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0/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:
      sample2() in boost_practice-bc871d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
boost: stable 1.66.0 (bottled), HEAD
Collection of portable C++ source libraries
https://www.boost.org/
/usr/local/Cellar/boost/1.65.1 (12,681 files, 432.1MB) *
   Built from source on 2017-11-17 at 14:24:23 with: --c++11
#include <vector>
#include <functional>
#include <string>

int main() {
    std::vector<std::string> str_values = {"abc", "bde"};
    auto count2 = std::count_if(str_values.begin(), str_values.end(),
                                std::mem_fn(&std::string::empty));
    (void)count2;
    return 0;
}
// explicit instantiation of std::string needed, otherwise we get a linker error with clang on osx
// thats a bug in libc++, because of interaction with __attribute__ ((__visibility__("hidden"), __always_inline__)) in std::string
template class std::basic_string<char>;