Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify header search path when using R CMD SHLIB to compile a C++ file?

Tags:

c++

r

boost

I'm trying to compile a C++ file which uses the Boost library on Mac OSX. For example, see the following "simple.cpp"

#include <boost/random.hpp>
using namesapce boost::math;

int main(){
    boost::mt19937 rng;
    rng.seed(static_cast<boost::uint32_t> (std::time(0)));

    return 0;
}

If I compile the file in the command shell with

g++ -I/usr/local/boost simple.cpp

then everything is fine. But I'd like to build a shared library so that I can use it to speed up my R project. If I use

R CMD SHLIB test.cpp

then it reports the header file can not be found. Is there a way to specify the search path for R CMD? Something like

R CMD SHLIB -I/usr/local/boost test.cpp
like image 762
William Zhang Avatar asked Sep 14 '12 00:09

William Zhang


1 Answers

You want to set PKG_CXXFLAGS -- see the fine manual's Section 1.2. "Using Makevars" as well as Section 5.5 "Creating shared objects" for details.

like image 97
Dirk Eddelbuettel Avatar answered Sep 28 '22 06:09

Dirk Eddelbuettel