[R-pkg-devel] How to retrieve a flag set in configure.ac (filled in Makevars.in) during package installation in an R or C++ script ?

Akshit Achara @ch@r@@k@h|t @end|ng |rom gm@||@com
Mon Aug 17 14:23:38 CEST 2020

Dear Andreas,

Thanks for your answer!

I also got an answer from Rcpp-devel list by Nik Pocuca. He suggested me to
create an .RData or .rda file
(say config.RData) in the data folder of my package and then execute the
statement given below in Makevars.in
to save the flag in the .RData file.
$(R_HOME)/bin/Rscript -e "LIBMINIZINC_PATH <- '@MZN_LIBS@';
save(LIBMINIZINC_PATH, file='../data/config.RData')"

This way the flag would be saved in the data file. Then in the script I
call data("config") and the LIBMINIZINC_PATH flag is
loaded in the global environment from where I can access and use it. I am
currently using this solution and haven't faced
any issues.


On Mon, Aug 17, 2020 at 3:36 PM Blätte, Andreas <andreas.blaette using uni-due.de>

> Dear Akshit,
> in the configure script of my package RcppCWB, I use the command line call
> 'R CMD config ...' to get the installation flags.
> Calling 'R CMD config' will display options. For your scenario, you can
> use 'R CMD config CPPFLAGS' to get the value of CPPFLAGS.
> To call R CMD config safely, you will need to prepend $R_HOME/bin. In the
> configure script of RcppCWB, I need to detect the compiler used and I do it
> using this snippet:
> CC_R=`$R_HOME/bin/R CMD config CC`
> More experienced people following R-package-devel than myself may be aware
> of a better solution, and I would also be happy to learn about it.
> Kind regards
> Andreas
> Am 15.08.20, 16:25 schrieb "R-package-devel im Auftrag von Akshit Achara"
> <r-package-devel-bounces using r-project.org im Auftrag von
> acharaakshit using gmail.com>:
>     Hi everyone,
>     Background:
>     The package rminizinc <https://github.com/acharaakshit/RMiniZinc>
> provides
>     an interface to MiniZinc
>     <https://www.minizinc.org/tutorial/minizinc-tute.pdf> in R. The
> package
>     provides various functionalities to parse, solve and manipulate
> MiniZinc
>     models. This is done by using the MiniZinc C++ API (libminizinc
>     <https://github.com/MiniZinc/libminizinc>).
>     The installation requires linking of the library an including the
> header
>     files for which PKG_LIBS flag(-L/path/to/libminizinc -lmzn) , and
>     PKG_CPPFLAGS (-I/path/to/libminizinc/include) are filled in Makevars.in
>     which is set by configure based on the path of the library provided by
> the
>     user using --configure-args or if the user doesn't provide any
> arguments, a
>     default path is passed from configure (using configure.ac).
>     Question:
>     In one of my Rcpp functions mzn_parse() which is used to parse MiniZinc
>     models, I sometimes need to use the files in the subdirectories of the
>     libminizinc library. To access these files, I need to use the path of
>     libminizinc (which can change per installation). I want to extract this
>     path from either Makevars or configure to use it in my package. Is
> there
>     any way I could retrieve this path in my scripts?
>     Please let me know if this question is not relevant to the mailing
> list.
>     The Makevars.in looks like this:
>     CXX_STD = CXX11
>     OBJECTS.tests = cpp_tests/test-runner.o cpp_tests/test-mzn_parse.o
>     cpp_tests/test-
>     set_params.o cpp_tests/test-mzn_eval.o cpp_tests/test-sol_parse.o
>     cpp_tests/test-
>     getMissingPars.o
>     OBJECTS.sources = RcppExports.o set_params.o mzn_parse.o mzn_eval.o
> sol_parse.o
>     getMissingPars.o
>     OBJECTS.helpers = filetoString.o helper_parse.o expDetails.o
> pathStringcheck.o
>     OBJECTS = $(OBJECTS.sources) $(OBJECTS.tests) $(OBJECTS.helpers)
>     $(SOURCES:.cpp=.o)
>     strippedLib: $(SHLIB)
>         if test -e "/usr/bin/strip"; then /usr/bin/strip --strip-debug
>     $(SHLIB); fi.phony: strippedLib
>     all: clean
>     clean:
>         rm -f $(OBJECTS.sources) $(OBJECTS.tests) $(OBJECTS.helpers)  *.so
>     Thanks!
>         [[alternative HTML version deleted]]
>     ______________________________________________
>     R-package-devel using r-project.org mailing list
>     https://stat.ethz.ch/mailman/listinfo/r-package-devel

	[[alternative HTML version deleted]]

More information about the R-package-devel mailing list