How to add flags to compiler flags

1,243 views
Skip to first unread message

Thomas Nyberg

unread,
Aug 4, 2014, 12:43:53 PM8/4/14
to rdev...@googlegroups.com
I'm trying to use load_all() to get some code running, but the error messages seem to indicate that I need the "-std=c++11" set for the code to compile correctly. But looking through devtools/searching the internet, I see no way to add flags to the compiler. Here is the error output:

> library(devtools)

Attaching package: devtools

The following objects are masked from package:utils’:

   
?, help

The following object is masked from package:base’:

    system
.file

> load_all()
Loading CCD
Re-compiling CCD
'/usr/lib/R/bin/R' --vanilla CMD INSTALL '/home/twn/Projects/ohdsi/OHDSI/CCD'  \
 
--library='/tmp/RtmpfjJYpm' --no-R --no-data --no-help --no-demo --no-inst  \
 
--no-docs --no-exec --no-multiarch --no-test-load --preclean

OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance.
* installing *source* package 'CCD' ...
** libs
g
++ -I/usr/share/R/include -DNDEBUG -I. -Iccd -DR_BUILD -DDOUBLE_PRECISION  -I"/home/twn/R/x86_64-pc-linux-gnu-library/3.0/Rcpp/include" -I"/home/twn/R/x86_64-pc-linux-gnu-library/3.0/BH/include" -I"/home/twn/R/x86_64-pc-linux-gnu-library/3.0/RcppEigen/include"  -UNDEBUG -Wall -pedantic -g -O0 -fpic  -O3 -pipe  -g  -c RcppCcdInterface.cpp -o RcppCcdInterface.o
In file included from /usr/include/c++/4.8/cstdint:35:0,
                 
from ccd/Types.h:11,
                 
from ccd/CcdInterface.h:23,
                 
from RcppCcdInterface.h:10,
                 
from RcppCcdInterface.cpp:10:
/usr/include/c++/4.8/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 
#error This file requires compiler and library support for the \
 
^
RcppCcdInterface.cpp:452:2: warning: identifier 'nullptr' is a keyword in C++11 [-Wc++0x-compat]
 
if (*model == nullptr) {
 
^
In file included from ccd/CcdInterface.h:23:0,
                 
from RcppCcdInterface.h:10,
                 
from RcppCcdInterface.cpp:10:
ccd
/Types.h:100:1: warning: scoped enums only available with -std=c++11 or -std=gnu++11 [enabled by default]
 
enum class ModelType {
 
^
ccd
/Types.h: In function 'bool bsccs::Models::requiresStratumID(bsccs::ModelType)':
ccd
/Types.h:114:23: error: 'ModelType' is not a class or namespace
 
return (modelType == ModelType::CONDITIONAL_LOGISTIC ||
                       
^
ccd
/Types.h:115:26: error: 'ModelType' is not a class or namespace
             modelType
== ModelType::CONDITIONAL_POISSON ||
                         
^
ccd
/Types.h:116:26: error: 'ModelType' is not a class or namespace
             modelType
== ModelType::SELF_CONTROLLED_MODEL);
                         
^
ccd
/Types.h: In function 'bool bsccs::Models::requiresCensoredData(bsccs::ModelType)':
ccd
/Types.h:120:23: error: 'ModelType' is not a class or namespace
 
return (modelType == ModelType::COX);
                       
^
ccd
/Types.h: In function 'bool bsccs::Models::requiresOffset(bsccs::ModelType)':
ccd
/Types.h:124:23: error: 'ModelType' is not a class or namespace
 
return (modelType == ModelType::SELF_CONTROLLED_MODEL);
                       
^
In file included from RcppCcdInterface.h:11:0,
                 
from RcppCcdInterface.cpp:10:
ccd
/priors/JointPrior.h: In member function 'virtual const string bsccs::priors::MixtureJointPrior::getDescription() const':
ccd
/priors/JointPrior.h:56:28: error: range-based 'for' loops are not allowed in C++98 mode
     
for (PriorPtr prior : uniquePriors) {
                           
^
In file included from ccd/CyclicCoordinateDescent.h:13:0,
                 
from RcppCcdInterface.cpp:14:
ccd
/engine/AbstractModelSpecifics.h: At global scope:
ccd
/engine/AbstractModelSpecifics.h:23:1: warning: scoped enums only available with -std=c++11 or -std=gnu++11 [enabled by default]
 
enum class ModelType; // forward declaration
 
^
ccd
/engine/AbstractModelSpecifics.h:23:1: warning: elaborated-type-specifier for a scoped enum must not use the 'class' keyword [enabled by default]
RcppCcdInterface.cpp: In function 'Eigen::MatrixXd ccdGetFisherInformation(SEXP, SEXP)':
RcppCcdInterface.cpp:76:11: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
     
for (auto it = covariates.begin(); it != covariates.end(); ++it) {
           
^
RcppCcdInterface.cpp:76:16: error: 'it' does not name a type
     
for (auto it = covariates.begin(); it != covariates.end(); ++it) {
               
^
RcppCcdInterface.cpp:76:41: error: expected ';' before 'it'
     
for (auto it = covariates.begin(); it != covariates.end(); ++it) {
                                         
^
RcppCcdInterface.cpp:76:41: error: 'it' was not declared in this scope
RcppCcdInterface.cpp: In static member function 'static bsccs::ModelType bsccs::RcppCcdInterface::parseModelType(const string&)':
RcppCcdInterface.cpp:332:40: error: 'bsccs::ModelType' is not a class or namespace
   bsccs
::ModelType modelType =  bsccs::ModelType::LOGISTIC;
                                       
^
RcppCcdInterface.cpp:334:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::SELF_CONTROLLED_MODEL;
                       
^
RcppCcdInterface.cpp:336:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::CONDITIONAL_POISSON;
                       
^
RcppCcdInterface.cpp:338:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::CONDITIONAL_LOGISTIC;
                       
^
RcppCcdInterface.cpp:340:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::LOGISTIC;
                       
^
RcppCcdInterface.cpp:342:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::NORMAL;
                       
^
RcppCcdInterface.cpp:344:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::POISSON;
                       
^
RcppCcdInterface.cpp:346:23: error: 'bsccs::ModelType' is not a class or namespace
    modelType
= bsccs::ModelType::COX;
                       
^
RcppCcdInterface.cpp: In member function 'virtual void bsccs::RcppCcdInterface::initializeModelImpl(bsccs::ModelData**, bsccs::CyclicCoordinateDescent**, bsccs::AbstractModelSpecifics**)':
RcppCcdInterface.cpp:452:16: error: 'nullptr' was not declared in this scope
 
if (*model == nullptr) {
               
^
make
: *** [RcppCcdInterface.o] Error 1
ERROR
: compilation failed for package 'CCD'
* removing '/tmp/RtmpfjJYpm/CCD'
Error: Command failed (1)
Execution halted

Thanks for any help!

Thomas Nyberg

unread,
Aug 4, 2014, 1:37:18 PM8/4/14
to rdev...@googlegroups.com
It appears that adding an environment variable of 'PKG_CXXFLAGS=-std=c++11' fixes this problem. I'm not sure why I didn't try this earlier...

ccd
/Types.h: In function<span style="color: #000;" class="
...

Winston Chang

unread,
Aug 4, 2014, 3:46:58 PM8/4/14
to Thomas Nyberg, rdev...@googlegroups.com
Have you tried using a Makevars file? For example:

It's also documented (confusingly) in Writing R extensions:

-Winston


--
You received this message because you are subscribed to the Google Groups "devtools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rdevtools+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Thomas Nyberg

unread,
Aug 5, 2014, 10:03:29 AM8/5/14
to rdev...@googlegroups.com, tomn...@gmail.com
Yes the project I was trying to compile apparently does have a Makevars file and adding the line

'PKG_CXXFLAGS = -std=c++11'

seems also to solve the problem. The Makevars file already had the following line '

CXX_STD = CXX11

It's pretty clear that the author meant for that flag to do what I wanted. Is that not the correct flag to use?

P.S. After reading that link, I see the following about Makevars:

"Also, do not set variables such as CPPFLAGS, CFLAGS etc.: these should be settable by users (sites) through appropriate personal (site-wide) Makevars files. See Customizing package compilation in R Installation and Administration,"

So I guess maybe the point is that I'm expected to have my own Makevars file which I keep updated myself...

Thanks for all the information! I should definitely now have enough info to figure out all the build stuff from here!

Cheers,
Thomas
RcppCcdInterface.<span style="co
...

Thomas Nyberg

unread,
Nov 13, 2014, 4:46:33 PM11/13/14
to rdev...@googlegroups.com, tomn...@gmail.com
I'm coming back to this because I never fully resolved this issue. In a redhat box I have running gcc 4.8.3 20140911 (Red Hat 4.8.3-7), only using the variable 'CXX_STD = CXX11' works fine, but on a newly setup Linux Mint system with gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2, that flag alone doesn't seem to work. In that case I need to use 'PKG_CXXFLAGS = -std=c++11'. Of course, it could be some other issue other than just redhat vs. linux mint, but that's really the only difference in the setup. In both cases, I've compiled R myself, installed devtools (and hence Rcpp) from cran, etc. Why isn't the 'CXX_STD = CXX11' flag being accepted?
...
Reply all
Reply to author
Forward
0 new messages