[Rcpp-devel] How to use Rcpp with Qt Creator (Mac)?

Dirk Eddelbuettel edd at debian.org
Sat May 16 03:25:33 CEST 2015


On 16 May 2015 at 01:55, Klemens Weigl wrote:
| Hi!
| 
| I would like to use Rcpp (Rcpp.h) with Qt Creator and a Mac.
| 
| So far I installed Rcpp successfully with RStudio. When I wanted to use it in a
| Qt project it always gives me the answer: 'Rcpp.h' file not found.
| 
| 
| In the Terminal I found the directory in: 
| cd /Library/Frameworks/R.framework/Resources/library
| in the .Pro-File (of the project) I tried:
| INCLUDEPATH += /Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/
| include
| LIBS += -I/Users/xy/Library/ -framework R
| 
| Exists there a solution to access directly to Rcpp.h via Qt when it was
| installed with RStudio?
| 
| I would appreciate if someone has got an idea/link/blog... to enable Rcpp.h
| also in Qt with a Mac!

The general mechanism with Qt -- on _any_ platform -- with to use the .pro
file to create an appropriate Makefile.

On my Linux box, and using _the working and documented example for RInsite_ :

edd at max:~/git/rinside/inst/examples/qt(master)$ grep RCPPINCL qtdensity.pro 
RCPPINCL =              $$system($$R_HOME/bin/Rscript -e \"Rcpp:::CxxFlags\(\)\")
QMAKE_CXXFLAGS +=       $$RCPPWARNING $$RCPPFLAGS $$RCPPINCL $$RINSIDEINCL
edd at max:~/git/rinside/inst/examples/qt(master)$

You then run qmake:

edd at max:~/git/rinside/inst/examples/qt(master)$ qmake 
edd at max:~/git/rinside/inst/examples/qt(master)$ grep INCPATH Makefile | head -1
INCPATH       = -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtSvg -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64
edd at max:~/git/rinside/inst/examples/qt(master)$ 

This now took the _abstract definition of 'ask R where Rcpp says its headers
are' and encode it in a way that make understands.

Now we can build:

edd at max:~/git/rinside/inst/examples/qt(master)$ make 
edd at max:~/git/rinside/inst/examples/qt(master)$

[ Using qt5 on Ubuntu 15.05, that currently fails with a linking error
  main.o:(.bss+0x0): multiple definition of `R_running_as_main_program'
  but I am pretty certain this still worked just a few weeks/months ago under
  the previous Ubuntu release. ]


In any event, the main story here is that _building programs with Qt is
different_ and you need to learn how to tell the Qt build framework where the
Rcpp resources are.

Hope this helps,  Dirk

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list