C++14 standard on Ubuntu 14.04 servers

We recently updated our firm’s R package to be Stanified using the method described here: https://cran.r-project.org/web/packages/rstantools/vignettes/minimal-rstan-package.html

The issue is that we’re deploying it to our servers which run Ubuntu 14.04 and I’m getting the following error when I try installing the package:

Error in .shlib_internal(args) : 
  C++14 standard requested but CXX14 is not defined

Any tips on what to do? Can I just change the Makevars file to use C++11?

Jim

1 Like

Stan technically requires as much of C++14 as is implemented in Rtools, but I think there is currently nothing that uses syntax that is not defined by the C++11 standard. That may not be true for long though.

I think it would work as is on Ubuntu 14.04 (srsly?) as long as it has R >= 3.4, which you may have to compile from source or get from a extra repository or something.

Or maybe you just need to put

CXX14 = g++-5

or whatever in the ~/.R/Makevars file

1 Like

Just found this which describes the problem. Downgrading to 11 for the moment then, and will pester the engineers to upgrade Ubuntu. Thanks Ben!

http://dirk.eddelbuettel.com/blog/2017/06/13/

@bgoodri Thanks for the above – the downgrade worked a treat.

Jim

That worked for me. But after some compilation and linking steps, I got an error:

/usr/bin/ld: chains.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC
chains.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status
make: *** [rstan.so] Error 1
ERROR: compilation failed for package ‘rstan’

System information:

$ lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch
Distributor ID: RedHatEnterpriseServer
Description:    Red Hat Enterprise Linux Server release 7.4 (Maipo)
Release:        7.4
Codename:       Maipo

R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)

Did you try recompiling it with -fPIC in CXXFLAGS?

I would recommend installing new version of gcc: see here https://askubuntu.com/questions/466651/how-do-i-use-the-latest-gcc-on-ubuntu/581497#581497

And here
https://docs.travis-ci.com/user/languages/cpp/
since travis-ci uses Ubuntu 14.04.

I added CXXFLAGS = -fPIC to the Makevars file, but still got the same error. I’m afraid I don’t have permission to install a more recent g++ in this computer. I could request it, but it’s not guaranteed to happen.

Actually, I don’t see the argument -fPIC in the compiler call. So that change to Makevars didn’t seem to make an effect.

Well, g++-4.8 isn’t adequate for Stan >= 2.18 anyway, so I would go ahead and request the upgrade.

Are you multiarching or something? Googling for “relocation R_X86_64_32 against `.rodata’ can not be used when making a shared object” yields a bunch of hits.

OK, so adding CXX14 = g++ -fPIC to Makevars worked.

for a few more days anyway

OK, thanks! The latest gcc I see is 8.2. I’ll try to get g++ updated.

After installing gcc tools 8.2, I’m getting an error when trying to install rstan-2.18.1 (it seems compiling terminated successfully):

** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
*** copying figures
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed for ‘rstan’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/bacalfa/R/x86_64-pc-linux-gnu-library/3.5/rstan/libs/rstan.so':
  /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by /home/bacalfa/R/x86_64-pc-linux-gnu-library/3.5/rstan/libs/rstan.so)
Error: loading failed
Execution halted
ERROR: loading failed

Any ideas?

What is the content of the ~/.R/Makevars file ?

CXX14 = /software/gcc/8.2.0/bin/g++
CXX14FLAGS = -fPIC

Google seems to suggest that you have an older version of libstdc++ than the one that should be present and found for g++-8. Maybe try to install the libstdc++-8-dev package?