Page 1 of 1

Setting compilation options specified by external scripts

Posted: Thu Feb 24, 2011 3:28 am
by rayohauno
Hi,

I'm compiling a project that uses some precompiled library (I'm trying to integrate
R C++ code (see http://www.r-project.org/) in a common C++ project). In order to
compile that library it is required to pass to the g++ linker some options (flags?).
The options (flags) may vary from system to system, so one must call a script (or program)
that replies with the right/specific flags for each system.

I do that writing in (right click on the project name) -> Settings -> Linker -> Options the
following:

Code: Select all

`usr/lib64/R/bin/Rscript -e "Rcpp:::LdFlags()"`
and it works. In fact if in a terminal I write:

Code: Select all

$ /usr/lib64/R/bin/Rscript -e "Rcpp:::LdFlags()"
its replies:

Code: Select all

-L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp -Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib
and that is ok. Now, the path to the script may also vary from system to system. In my
case the path is:

Code: Select all

/usr/lib64/R/bin/

from it, the "first part":

Code: Select all

/usr/lib64/R/
is the system specific. This first part of the path can be obtained calling an executable named R that
is exported to the system PATH (when R is installed) trough the following command:

Code: Select all

$ R RHOME
which returns:

Code: Select all

/usr/lib64/R
So I want to use that in order to make non system specific the "options" line
that I pass to the compiler. I have tried two things. One is to change:

Code: Select all

`usr/lib64/R/bin/Rscript -e "Rcpp:::LdFlags()"`
by:

Code: Select all

`$(R RHOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
but it doesn't work (I'm not a linux expert). Then I have tried
by means of exporting what R RHOME returns. That is, in:
(right click on project name) -> Settings -> PreBuild
I add the follwong command line to run in the pre-build event:

Code: Select all

export R_HOME=$(R RHOME)
and then change:

Code: Select all

`usr/lib64/R/bin/Rscript -e "Rcpp:::LdFlags()"`
by:

Code: Select all

`$(R_HOME)/bin/Rscript -e "Rcpp:::LdFlags()"`
but it also doesn't work.

Which is the right way of do that?

Best Regards

Re: Setting compilation options specified by external scripts

Posted: Thu Feb 24, 2011 4:01 pm
by eranif
In the linker options, add this:

Code: Select all

$(shell $(shell R RHOME)/bin/Rscript -e "Rcpp:::LdFlags()")
It will do what you want.
Eran

Re: Setting compilation options specified by external scripts

Posted: Thu Feb 24, 2011 7:26 pm
by rayohauno
Thanks Eran,

Now, I'm figuring out that this is "Make coding" (I do not know how to name this, I'm not a programmer). Also, after post I have tried
something similar, I've tried this (between several other intents):

Code: Select all

$(shell $(R RHOME)/bin/Rscript -e "Rcpp:::LdFlags()")
but it does not work. I was close.

Best Regards