Skip to content

[R-pkg-devel] Rcpp with clang++ -stdlib=libc++ ?

3 messages · Jens Oehlschlägel, Dirk Eddelbuettel, Kevin Ushey

#
I can compile a package under clang++ with -stdlib=libstdc++, but with -stdlib=libc++ I get

"
In file included from /home/jo/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/Rcpp/r/headers.h:67:
/home/jo/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/Rcpp/platform/compiler.h:100:10: fatal error: 'cmath' file not found
#include <cmath>
???????? ^~~~~~~
1 error generated.
"

Is there any howto for using Rcpp with -stdlib=libc++ ?
Greetings from Munich

Jens Oehlschl?gel

?
P.S.

Package Makevars
CXX_STD = CXX17
PKG_CXXFLAGS=-O3 -march=native -pthread
PKG_LIBS=-latomic -pthread

~.R/Makevars
CXX17 = clang++ -stdlib=libc++
CXX17FLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 -g $(LTO)
CXX17STD = -std=c++17
[1] ?1.0.5?
?????????????? _??????????????????????????
platform?????? x86_64-pc-linux-gnu????????
arch?????????? x86_64?????????????????????
os???????????? linux-gnu??????????????????
system???????? x86_64, linux-gnu??????????
status????????????????????????????????????
major????????? 4??????????????????????????
minor????????? 0.2????????????????????????
year?????????? 2020???????????????????????
month????????? 06?????????????????????????
day??????????? 22?????????????????????????
svn rev??????? 78730??????????????????????
language?????? R??????????????????????????
version.string R version 4.0.2 (2020-06-22)
nickname?????? Taking Off Again
#
Hi Jens,
On 11 September 2020 at 21:00, Dr. Jens Oehlschl?gel wrote:
| I can compile a package under clang++ with -stdlib=libstdc++, but with -stdlib=libc++ I get
| 
| "
| In file included from /home/jo/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/Rcpp/r/headers.h:67:
| /home/jo/R/x86_64-pc-linux-gnu-library/4.0/Rcpp/include/Rcpp/platform/compiler.h:100:10: fatal error: 'cmath' file not found
| #include <cmath>
| ???????? ^~~~~~~
| 1 error generated.
| "
| 
| Is there any howto for using Rcpp with -stdlib=libc++ ?

That has zero to do with Rcpp.  You are lacking a C++ library header when
switching the C++ standard library along with clang. Nothing that Rcpp ships,
or governs, or selects.  

I am forgetting the fine details here (and someone may hopefully fill in
fuller details) but in short, "that is just the way it is".  I think we
simply pivot back to the g++ standard C++ library even when using clang++.

Cheers from Chicago,  Dirk

| Greetings from Munich
| 
| Jens Oehlschl?gel
| 
| ?
| P.S.
| 
| Package Makevars
| CXX_STD = CXX17
| PKG_CXXFLAGS=-O3 -march=native -pthread
| PKG_LIBS=-latomic -pthread
| 
| ~.R/Makevars
| CXX17 = clang++ -stdlib=libc++
| CXX17FLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2 -g $(LTO)
| CXX17STD = -std=c++17
| 
| > packageVersion("Rcpp")
| [1] ?1.0.5?
| 
| > version
| ?????????????? _??????????????????????????
| platform?????? x86_64-pc-linux-gnu????????
| arch?????????? x86_64?????????????????????
| os???????????? linux-gnu??????????????????
| system???????? x86_64, linux-gnu??????????
| status????????????????????????????????????
| major????????? 4??????????????????????????
| minor????????? 0.2????????????????????????
| year?????????? 2020???????????????????????
| month????????? 06?????????????????????????
| day??????????? 22?????????????????????????
| svn rev??????? 78730??????????????????????
| language?????? R??????????????????????????
| version.string R version 4.0.2 (2020-06-22)
| nickname?????? Taking Off Again
| 
| ______________________________________________
| R-package-devel at r-project.org mailing list
| https://stat.ethz.ch/mailman/listinfo/r-package-devel
#
My understanding is that many Linux OSes package the clang compiler, the
libc++ standard library, and the headers used by the libc++ standard
library separately. To install those headers, you likely need (e.g. on
Ubuntu):

    sudo apt install libc++-dev libc++abi-dev

to be able to build and compile programs against libc++.

This also comes with the caveat that mixing programs built against
different standard library implementations is in general a bad idea, so you
may see issues if you mix libraries compiled with libstdc++ and libc++ in
the same R session. (This can come up with R packages that link to other
libraries installed on the system, which will typically be built with and
linked against the "default" system compiler + standard library
implementations.) I'm not sure if this will be an issue in practice with
what you're doing, but it's worth being aware of.

Best,
Kevin
On Sat, Sep 12, 2020 at 5:50 AM Dirk Eddelbuettel <edd at debian.org> wrote: