How to update a package that has StanHeaders and rstan in its LinkingTo

Sure. I will take a look.

Hi, Paul, I am Dieter Menne, just mistyped my name when I registered as denne

MAKEFLAGS = -j4
CXX14 = g++ # g++ or clang++ if you have that
CXX14FLAGS = -O3

I know who you are ;-)

I can build and install your package from source using Win10, R 3.5.1, rstan 2.18.1 and g++ from Rtools 3.5 under the following settings:

Makevars:

CXX14 = g++ -std=c++1y
CXX14FLAGS = -O3 -Wno-unused-variable -Wno-unused-function

Path:

C:\Rtools\bin
C:\Rtools\mingw_64\bin

(the path shouldn’t include C:\Rtools\mingw_32\bin)

gcc version 6.2.1 20160825

I noted that this version from sourceforge mingw is rather old. Do you know of a newer build

We haven’t done any testing with gcc 6.2 on Windows. I will start another thread in a few days about using gcc 8.2.

I understand, it compiled with an error message asking for c++11, which I found braindead. Will try

-std=c++1y

Thanks, Paul, your settings, especially -std=c++1y works with the 3.5 toolchain. The critical question now is how I tell this to CRAN. Put it into the project makevars?

As far I understand from below, c++1y means c++14 to older compilers.

Yes, it’s there. I just followed the instructions here and here, and now get additional warnings from R CMD check:

* DONE
Status: 2 WARNINGs

See
  ‘/bmlm.Rcheck/00check.log’
for details.


checking compilation flags used ... WARNING
Compilation used the following non-portable flag(s):
  ‘-Wno-macro-redefined’ ‘-Wno-unknown-pragmas’ ‘-Wno-unused-function’
  ‘-Wno-unused-variable’
including flag(s) suppressing warnings

checking compiled code ... WARNING
File ‘bmlm/libs/bmlm.so’:
  Found ‘_abort’, possibly from ‘abort’ (C)
    Object: ‘Modules.o’

Compiled code should not call entry points which might terminate R nor
write to stdout/stderr instead of to the console, nor use Fortran I/O
nor system RNGs.

See ‘Writing portable packages’ in the ‘Writing R Extensions’ manual.
R CMD check results
0 errors | 2 warnings | 0 notes

R CMD check succeeded

My ~/.R/Makevars looks like this:

R_XTRA_CPPFLAGS =  -I$(R_INCLUDE_DIR)   #set_by_rstan
CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++
CXX98=/usr/local/clang4/bin/clang++
CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++
LDFLAGS=-L/usr/local/clang4/lib

CXX14FLAGS=-O3 -mtune=native -march=native -Wno-unused-variable -Wno-unused-function  -Wno-macro-redefined -Wno-unknown-pragmas

CC=clang
CXX14=clang++ -arch x86_64 -ftemplate-depth-256

There are multiple entries for some keys, but I’ve left them as is because that’s what’s created when following the steps outlined in the links above.


Update:
Removing this line

R_XTRA_CPPFLAGS =  -I$(R_INCLUDE_DIR)   #set_by_rstan

Removes the warning

checking compiled code ... WARNING
File ‘bmlm/libs/bmlm.so’:
  Found ‘_abort’, possibly from ‘abort’ (C)
    Object: ‘Modules.o’

Is it safe to remove that line? And if so, can I also safely remove the other flags that result in warnings?

@denne It should work on CRAN as long as CXX_STD = CXX14 is in src/Makevars.win but you should try uploading to http://win-builder.r-project.org/ again in order to verify it is passing R CMD check there.

@matti yes get rid of that line

Okay, I removed it and the other flags which were giving warnings with R CMD check. My Makevars looks like this now (it’s created as described here):

CC=/usr/local/clang4/bin/clang
CXX=/usr/local/clang4/bin/clang++
CXX1X=/usr/local/clang4/bin/clang++
CXX98=/usr/local/clang4/bin/clang++
CXX11=/usr/local/clang4/bin/clang++
CXX14=/usr/local/clang4/bin/clang++
CXX17=/usr/local/clang4/bin/clang++
LDFLAGS=-L/usr/local/clang4/lib

CXX14FLAGS=-O3 -mtune=native -march=native

CC=clang
CXX14=clang++ -arch x86_64 -ftemplate-depth-256

No more warnings. Unless I’m missing something (are the -Wno flags necessary for something else?), I’m going to submit to CRAN soon.

Thanks so much for the help… Much appreciated.

The -wno- flags are actually illegal according to CRAN, so go ahead and upload to http://win-builder.r-project.org/ again to make sure it is all fine.

Win builder now gives an error about rstan versions:

* using log directory 'd:/RCompile/CRANguest/R-devel/bmlm.Rcheck'
* using R Under development (unstable) (2018-10-12 r75434)
* using platform: x86_64-w64-mingw32 (64-bit)
* using session charset: ISO8859-1
* checking for file 'bmlm/DESCRIPTION' ... OK
* this is package 'bmlm' version '1.3.8'
* checking CRAN incoming feasibility ... Note_to_CRAN_maintainers
Maintainer: 'Matti Vuorre <mv2521@columbia.edu>'
* checking package namespace information ... OK
* checking package dependencies ... ERROR
Packages required and available but unsuitable versions: 'rstan', 'rstan'

See section 'The DESCRIPTION file' in the 'Writing R Extensions'
manual.
* DONE
Status: 1 ERROR

Which is bizarre because the earlier submission (by @bgoodri) with exact same DESCRIPTION file gave no errors/warnings.

Do I have to wait until the new rstan version is available throughout CRAN (?) or can I submit right away?

I would wait. It should only be a day or so.

OK, thank you!

I just put rstan_2.18.1 back on winbuilder until winbuilder realizes that rstan_2.18.1 is on CRAN

Same error for me

Packages required and available but unsuitable versions: 'rstan' 'rstan'

Everything is fine when you upload it to the devel-version of winbuilder.

That ought to be good enough for you to upload.

Just did, immediately accepted by CRAN. Thanks

In the event it helps someone, here is how I got trialr to build on my Windows machine today.

The tail end of my built process reported:

g++ -std=c++1y -shared -s -static-libgcc -o trialr.dll tmp.def Modules.o RcppExports.o trialr-init.o -LC:/Users/Kristian Brock/Documents/R/win-library/3.5/StanHeaders/libs/x64 -lStanHeaders -LC:/PROGRA~1/R/R-35~1.1/bin/x64 -lR
trialr-init.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status
no DLL was created
ERROR: compilation failed for package 'trialr'
* removing 'C:/Users/Kristian Brock/Documents/R/win-library/3.5/trialr'
In R CMD INSTALL

Exited with status 1.

Reinstalling R, rstan, RStudio, all packages did not solve it.
The comment from @paul.buerkner above

(the path shouldn’t include C:\Rtools\mingw_32\bin )

put me onto a solution.

I had re-installed Rtools (to no avail) but I had not unsintalled the old version first. Thus, my path still referred to _32 g++.

Uninstalling Rtools, then re-installing v3.4, suppressing the installation of the 32bit components (just to be sure), making sure to select the “edit PATH” option, reboot, and the package built.

Now, I am still getting the following problem on TravisCI:

trying URL 'http://cloud.r-project.org/src/contrib/rstan_2.18.1.tar.gz'
Content type 'application/x-gzip' length 833755 bytes (814 KB)
==================================================
downloaded 814 KB

...

Error in .shlib_internal(args) : 
  C++14 standard requested but CXX14 is not defined
* removing ‘/home/travis/R/Library/rstan’
Error in i.p(...) : 
  (converted from warning) installation of package ‘rstan’ had non-zero exit status
Calls: <Anonymous> ... with_rprofile_user -> with_envvar -> force -> force -> i.p
Execution halted

I am not sure what to do about that.

However, I can build my package locally, which is more than I could do this morning.