RIOS X Mavericks上使用clang++构建的内部示例在链接上找不到STL标准库

RInside example build using clang++ on OS X Mavericks cannot find STL standard library on linking

本文关键字:链接 找不到 STL 标准 Mavericks clang++ RIOS 构建 内部      更新时间:2023-10-16

我最近在OS X 10.9.1上使用命令行工具迁移到C++11和Xcode 5,使用Homebrew安装了boost 1.55,并将编译器从g++更改为clang++(如本文所述:使用Xcode 5.0和Rcpp时出错)。当在R中运行时,编译器更改修复了Rcpp。但我在编译RInside示例时遇到了问题(过去工作得很好)。

我重新下载了RInside并解压缩了tar,转到examples/standard目录并做了make cleanmake all。看起来任何STL都没有从该目录链接到。如何使RInside链接到Makefile中的适当STL?

我在一个单独的项目中使用来自Netbeans的STL,并在那里使用clang++进行构建。然而,当我在Netbeans上尝试一个RInside项目时,我会遇到同样的问题:Undefined symbols for architecture x86_64。我需要在某个地方下载STL或RInside的64位版本吗?

我是否仍然需要在某个地方更新/更改配置,我是否下载了错误的包,或者它是Makefile中需要更改的示例的设置?

这是来自make all:的第一个呼叫

clang++ -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include -I/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RInside/include -mtune=native -g -O2 -Wall -pedantic -Wconversion -Wall -I/usr/local/include   rinside_callbacks0.cpp  -F/Library/Frameworks/R.framework/.. -framework R  -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/Library/Frameworks/R.framework/Resources/lib -lRlapack /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a /Library/Frameworks/R.framework/Versions/3.0/Resources/library/RInside/lib/libRInside.a -o rinside_callbacks0

输出的开始:

Undefined symbols for architecture x86_64:
"std::string::find_last_of(char, unsigned long) const", referenced from:
demangler_one(char const*) in libRcpp.a(api.o)
"std::string::find(char const*, unsigned long) const", referenced from:
short_file_name(char const*) in libRcpp.a(api.o)
"std::string::size() const", referenced from:
std::basic_string<char, std::char_traits<char>, std::allocator<char> > std::operator+<char, std::char_traits<char>, std::allocator<char> >(char const*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in libRcpp.a(api.o)
MemBuf::add(std::string const&) in libRInside.a(MemBuf.o)
"std::string::c_str() const", referenced from:
RInside::parseEval(std::string const&, SEXPREC*&) in libRInside.a(RInside.o)
SEXPREC* Rcpp::pairlist<Rcpp::Function, Rcpp::traits::named_object<SEXPREC*>, Rcpp::traits::named_object<SEXPREC*> >(Rcpp::Function const&, Rcpp::traits::named_object<SEXPREC*> const&, Rcpp::traits::named_object<SEXPREC*> const&) in libRInside.a(RInside.o)
short_file_name(char const*) in libRcpp.a(api.o)
string_to_try_error(std::string const&) in libRcpp.a(api.o)
Rcpp::RObject::AttributeProxy::set(SEXPREC*) const in libRcpp.a(api.o)
demangle(std::string const&) in libRcpp.a(api.o)
Rcpp::RObject::AttributeProxy::get() const in libRcpp.a(api.o)

在错误消息的末尾:

ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

我建议您学习/关注r-sig-mac列表上的讨论,以及SO上的讨论(例如,搜索[rcpp] mavericks)。

我怀疑您所需要的只是将CXXCXXFLAGS变量扩展为

CC=clang
CXX=clang++
CXXFLAGS=-stdlib=libc++ -std=c++11

加上诸如CCD_ 8之类的任何其它选项。

在OS X 10.9.1上降级到Xcode 4.6.3并使用clang++和C++11(Netbeans中的设置没有其他更改)后,我在Netbeans上得到了这个例子。它还使用C++98处理g++(或clang++)。Xcode 5中的默认库看起来是libc++(支持C++11的LLVM C++标准库),但我需要libstdc++(GNU C++标准库-早期Xcode版本的默认库)来链接它。在更改~/.R/Makevars文件CXXFLAGS="-stdlib=libstdc++ -std=c++11 -mtune=native -g -O3 -Wall -pedantic -Wconversion"中的内容以及clang++的更改之后,我得到了要构建的示例。我通过重新升级到Xcode 5来确认这一行为,并在Netbeans中得到了相同的错误,但在示例上没有(由于libstdc++标志,现在构建了示例)。当我在Netbeans中添加-stdlib=libstdc++作为附加标志时,它再次构建。

就像一个fyi,以防其他人在构建示例时遇到问题。在Netbeans中,编译和链接步骤是:

"/Applications/Xcode.app/Contents/Developer/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
"/Applications/Xcode.app/Contents/Developer/usr/bin/make"  -f nbproject/Makefile-Debug.mk dist/Debug/GNU-MacOSX/callingrproject
mkdir -p build/Debug/GNU-MacOSX
rm -f "build/Debug/GNU-MacOSX/main.o.d"
clang++ -stdlib=libstdc++   -c -g -I. -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/library/Rcpp/include -I/Library/Frameworks/R.framework/Resources/library/RInside/include -I/usr/local/Cellar -std=c++98 -MMD -MP -MF "build/Debug/GNU-MacOSX/main.o.d" -o build/Debug/GNU-MacOSX/main.o main.cpp
mkdir -p dist/Debug/GNU-MacOSX
clang++ -o dist/Debug/GNU-MacOSX/callingrproject build/Debug/GNU-MacOSX/main.o -L/Library/Frameworks/R.framework/Resources/lib -L/Library/Frameworks/R.framework/Resources/library/Rcpp/lib -L/Library/Frameworks/R.framework/Resources/library/RInside/lib -L/Library/Frameworks/R.framework/Libraries -L/Library/Frameworks/R.framework/Resources/lib -L/Library/Frameworks/R.framework/Resources/library -L/Library/Frameworks/R.framework/Resources/modules -lRcpp -lRInside -lRlapack -lRblas -F/Library/Frameworks/R.framework/.. -framework R -stdlib=libstdc++

示例构建是:

clang++ -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/include -I/Library/Frameworks/R.framework/Versions/3.0/Resources/library/RInside/include -stdlib=libstdc++ -std=c++11 -mtune=native -g -O3 -Wall -pedantic -Wconversion -Wall -I/usr/local/include   rinside_callbacks0.cpp  -F/Library/Frameworks/R.framework/.. -framework R  -L/Library/Frameworks/R.framework/Resources/lib -lRblas -L/Library/Frameworks/R.framework/Resources/lib -lRlapack /Library/Frameworks/R.framework/Versions/3.0/Resources/library/Rcpp/lib/libRcpp.a /Library/Frameworks/R.framework/Versions/3.0/Resources/library/RInside/lib/libRInside.a -o rinside_callbacks0