Question

I recently moved to C++11 and Xcode 5 with command line tools on OS X 10.9.1, installed boost 1.55 using Homebrew and changed the compiler from g++ to clang++ (as mentioned in this post: Error when with Xcode 5.0 and Rcpp). The compiler change fixed Rcpp when running in R. But I am having issues with compiling the RInside examples (which used to work just fine).

I re-downloaded RInside and unzipped the tar, went to the examples/standard directory and did a make clean and make all. It looks like any STL is not being linked to from this directory. How do I make RInside link to the appropriate STL in the Makefile?

I am using STL from Netbeans in a seperate project and building using clang++ works there. However, when I try an RInside project on Netbeans I get the same issue: Undefined symbols for architecture x86_64. Do I need to download a 64 bit version of STL or of RInside somewhere ?

Am I still in need of updating/altering a config somewhere, did I download a wrong package or is it a setting in the Makefile for the examples that needs to change?

Here is the first call from 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

The beginning of the output:

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)

And at the end of the error messages:

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

Solution 2

I got the example to work from my Netbeans after downgrading to Xcode 4.6.3 on OS X 10.9.1 and using clang++ and C++11 (no other changes to the settings in Netbeans). It also worked on g++ (or clang++) using C++98. It looks like the default library in Xcode 5 was libc++ (LLVM C++ standard library with C++11 support) but what I needed for this to link was libstdc++ (GNU C++ standard library - default library for earlier Xcode versions). After changing that in the ~/.R/Makevars file CXXFLAGS="-stdlib=libstdc++ -std=c++11 -mtune=native -g -O3 -Wall -pedantic -Wconversion" along with the clang++ change I got the examples to build. I confirmed the behavior by re-upgrading to Xcode 5 and getting the same error in Netbeans but not on the samples (which now built because of the libstdc++ flag). When I added -stdlib=libstdc++ as an additional flag in Netbeans it built again.

Just as an fyi in case someone else hits a problem building the examples. In Netbeans the compile and links steps are:

"/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++

The example build was:

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

OTHER TIPS

I suggest you study / follow the discussions on the r-sig-mac list as well as here on SO (search for, say, [rcpp] mavericks).

I suspect that all you need is to expand your CXX and CXXFLAGS variables to say

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

plus whatever other options such as -O3 -Wall -pedantic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top