Problems linking to tbb with latest StanHeaders

I see

 * R
Error in parse(outFile) : 
  /private/var/folders/k3/6nvq5jhn0sd2545_70t8p5rr0000gn/T/RtmpjYVhrK/git2r-b1b726d49d03/StanHeaders/R/Flags.R:3:70: unexpected string constant
4:   if (isTRUE(as_character)) return(CXXFLAGS)
5:   cat(CXXFLAGS, "

I may have been installing the commit before this commit - I’ll try again.

Just fyi install_StanHeaders takes a long time to clone all the directories. Are there some binary files somewhere?

I must have fixed that 10 seconds after you started. Try it again. Sorry it takes so long. There are no binary files, but it has to download a lot of history for Stan. And I haven’t figured out how to get it to do a shallow git clone.

Right so unfortunately I get the same error…

This is despite the fact that the linker invocation now looks correct to me.

I’m not sure what’s gone wrong really.

This linker invocation (using develop StanHeaders) errors:

clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-headerpad_m  
  ax_install_names -undefined dynamic_lookup -single_module -multiply_defined     
suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o     
rater.so RcppExports.o stanExports_class_conditional_dawid_skene.o stanExpo   
 rts_dawid_skene.o stanExports_grouped_data.o stanExports_hierarchical_dawid_ 
   skene.o -L'/Library/Frameworks/R.framework/Versions/4.0/Resources/library/Rc   
 ppParallel/lib/' -Wl,-rpath,/Library/Frameworks/R.framework/Versions/4.0/Res    
ources/library/RcppParallel/lib/ -ltbb -ltbbmalloc -F/Library/Frameworks/R.f    
ramework/.. -framework R -Wl,-framework -Wl,CoreFoundation

whereas this one (my fork of rstantools) does not:

clang++ -mmacosx-version-min=10.13 -std=gnu++14 -dynamiclib -Wl,-
headerpad_max_install_names -undefined dynamic_lookup -single_module 
-multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr
/local/lib -o rater.so RcppExports.o stanExports_class_conditional_dawid_skene.o 
stanExports_dawid_skene.o stanExports_grouped_data.o 
stanExports_hierarchical_dawid_skene.o -L/Library/Frameworks/R.framework/Versions
/4.0/Resources/library/RcppParallel/lib/ -Wl,-rpath,/Library/Frameworks/R.framework
/Versions/4.0/Resources/library/RcppParallel/lib/ -ltbb -ltbbmalloc -F/Library
/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation

And the only difference I can see between the invocations is the lack of ‘’ around the path -L/Library/Frameworks/R.framework/Versions
/4.0/Resources/library/RcppParallel/lib/ in the second one.

I would be surprised if the quotation marks is what is messing things up but I pushed a version without them to GitHub.

Yeah, me too - it was just the only difference I could spot

Good news - I just installed StanHeaders from GitHub again (without the last commit to remove the quotes) and I was able to install the package successfully! I’m not sure why it didn’t work before.

Is there any timeline for the fixes to go to CRAN? I would imagine this would break other package depending on rstan.

Thanks your help + a fast super fast turnaround @bgoodri

In the morning.

1 Like

Notice I didn’t say which morning, but it turned out to be yesterday morning.

1 Like

Hi All,
I am trying to use precompiled Stan code in a R package. But I have not been able to figure out what is the resolve for this problem in Mac. My package compiles fine in Ubuntu. But the same code won’t compile in my mac book air. It comes out with the message:

In file included from /Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/rev/core.hpp:8:
/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/rev/core/init_chainablestack.hpp:8:10: fatal error: ‘tbb/task_scheduler_observer.h’ file not found
#include <tbb/task_scheduler_observer.h>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 warnings and 1 error generated.
make: *** [stanExports_spatial_model.o] Error 1
ERROR: compilation failed for package ‘xxxx’

I have installed StanHeaders from Github as suggested by bgoodri. That worked fine. But still my package won’t compile.
Many thanks for your kind reply.

Very best wishes, Sujit

Does your package use rstantools?

Hi Ben,
Thanks! Yes, I am using rstantools and other packages to compile. I have been able to compile my package in Ubuntu and Windows 10. I have updated almost everything in my mac book. Here are the details. Please let me know if you would like to know more.

R version 4.0.1 (2020-06-06) – “See Things Now”
Rstudio: Version 1.3.959
Mac OS: Catalina 10.15.5
Xcode: 11.5

I think all the dependency packages are installed already. Please see my list of installed packages below.

I get the following error:

/Library/Frameworks/R.framework/Versions/4.0/Resources/library/StanHeaders/include/stan/math/rev/core/init_chainablestack.hpp:8:10: fatal error: 'tbb/task_scheduler_observer.h' file not found
#include <tbb/task_scheduler_observer.h>
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 warnings and 1 error generated.
make: *** [stanExports_gp_marginal.o] Error 1
ERROR: compilation failed for package ‘bmstdr’

Hi Sujit,

See this commit for how I got my package working with the lastest StanHeaders.

Basically:

  1. Rerun rstan_config() with rstantools 2.0.1
  2. Add RcppParallel to Imports and LinkingTo

You can see this took me a while to work out when you look at the commit message (from after a large rebase :) )

Hope that helps!

2 Likes

tbb header problem solved. Downgrading rstantools to version 2.0.0 worked for me.

devtools::install_version(“rstantools”, version = “2.0.0”)

I also added import RcppParallel using the Roxygen statement: #’ @import RcppParallel

Thanks!

1 Like