Setting compilation options specified by external scripts

General questions regarding the usage of CodeLite
rayohauno
CodeLite Curious
Posts: 2
Joined: Tue Feb 22, 2011 10:35 pm
Genuine User: Yes
IDE Question: C++
Contact:

Setting compilation options specified by external scripts

Post 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
User avatar
eranif
CodeLite Plugin
Posts: 6375
Joined: Wed Feb 06, 2008 9:29 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Setting compilation options specified by external scripts

Post 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
Make sure you have read the HOW TO POST thread
rayohauno
CodeLite Curious
Posts: 2
Joined: Tue Feb 22, 2011 10:35 pm
Genuine User: Yes
IDE Question: C++
Contact:

Re: Setting compilation options specified by external scripts

Post 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
Post Reply