rstudio / rmarkdown

Dynamic Documents for R
https://rmarkdown.rstudio.com
GNU General Public License v3.0
2.86k stars 967 forks source link

pdf knit failed on mac #1144

Closed zhiruiwang closed 6 years ago

zhiruiwang commented 6 years ago

When I knit a pdf using rmarkdown, it always return such error:

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/Library/Frameworks/R.framework/Versions/3.4.1-MRO/Resources/library/Rcpp/libs/Rcpp.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.4.1-MRO/Resources/library/Rcpp/libs/Rcpp.so, 6): Library not loaded: /usr/local/clang4/lib/libc++abi.dylib
  Referenced from: /Library/Frameworks/R.framework/Resources/lib/libc++.1.dylib
  Reason: image not found
Calls: :: ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
Execution halted

sessionInfo():

R version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

loaded via a namespace (and not attached):
 [1] compiler_3.4.1   backports_1.1.0  magrittr_1.5    
 [4] RevoUtils_10.0.5 rprojroot_1.2    htmltools_0.3.6 
 [7] tools_3.4.1      yaml_2.1.14      Rcpp_0.12.12    
[10] stringi_1.1.5    rmarkdown_1.6    knitr_1.17      
[13] stringr_1.2.0    digest_0.6.12    evaluate_0.10.1
yihui commented 6 years ago

Do you have a minimal reproducible example? Or do you mean this happens to all R Markdown documents?

You seem to be using Microsoft R Open, which could be a possible reason.

And is everything up-to-date? e.g. update.packages(ask = FALSE, checkBuilt = TRUE). Can you try to reinstall Rcpp if that does not fix your issue?

zhiruiwang commented 6 years ago

It seems like a problem of Rcpp and its compiler clang. Do you know how could I fix it?

> Rcpp::evalCpp('1+1')
/bin/sh: /usr/local/clang4/bin/clang++: No such file or directory
make: *** [file3e76680fbd3c.o] Error 127
/usr/local/clang4/bin/clang++  -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG   -I"/Library/Frameworks/R.framework/Versions/3.4.1-MRO/Resources/library/Rcpp/include" -I"/private/var/folders/1v/wz_prgn52n91b5x1byjxwnl00000gn/T/RtmpXqL3rj/sourceCpp-x86_64-apple-darwin15.6.0-0.12.12" -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include   -fPIC  -DU_STATIC_IMPLEMENTATION -Wall -mtune=core2 -g -O2 -I/opt/X11/include  -c file3e76680fbd3c.cpp -o file3e76680fbd3c.o
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir,  : 
  Error 1 occurred building shared library.
zhiruiwang commented 6 years ago

See the following link how it is fixed: https://github.com/RcppCore/Rcpp/issues/751

coatless commented 6 years ago

@yihui : If possible, could you add additional checks to the Rcpp engine for both macOS and windows?

For macOS: Starting with R 3.4.*, the toolchain for macOS changed (e.g. /usr/local/clang4).

For Windows: Users need to have Rtools on the PATH. However, the default installer does not require this change. Thus, we get errors on StackOverflow of:

Let me know if you would prefer I open a new ticket...

kevinushey commented 6 years ago

I don't think we should request any work from @yihui here. From what I can tell, binaries of Rcpp distributed by CRAN link to the copy of libc++ provided by R, so I don't know how @zhiruiwang got himself into this state.

kevin@cdrv:~/Library/R/3.4/library/Rcpp/libs
$ otool -L Rcpp.so
Rcpp.so:
        Rcpp.so (compatibility version 0.0.0, current version 0.0.0)
        /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libR.dylib (compatibility version 3.4.0, current version 3.4.1)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1259.11.0)
        /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

(maybe @zhiruiwang is using a checkpointed version of MRAN that's serving broken copies of Rcpp? I recall that was an issue briefly in the past, but CRAN quickly fixed the issue)

coatless commented 6 years ago

@kevinushey who would be the best person (or place) for this request? It's one of the biggest barriers of entry when coupling compiled code with the literate programming workflow that students are being encouraged to take.

zhiruiwang commented 6 years ago

@kevinushey I am using the following repo to download R packages, I think it is still up an up-to-date CRAN mirror?

options(repos = c(CRAN = "https://cran.revolutionanalytics.com"))

After I install the clang4 from this link: https://github.com/coatless/r-macos-clang, everything is solved. I checked the /usr/local/clang4 directory beforehand, there was only a lib folder under the directory, and only 4 dylib files under the lib. I do not know whether it is my own mac's problem, or all other mac has the same issue with their clang4.

kevinushey commented 6 years ago

The copy of Rcpp distributed from that CRAN mirror seems to work fine for me as well, and it also seems to work fine with a newly installed version of MRO on my macOS machine, so I suspect the issue you're encountering may be local (but I don't know what the underlying cause might be).

@coatless you might consider submitting a PR to knitr (assuming that Yihui would be willing to review that).

coatless commented 6 years ago

@kevinushey sounds good! More than happy to address this as it is frequently one of the top issues during OHs later in the semester... Despite plastering warnings, creating install guides, and even an installer... C'est la vie.

github-actions[bot] commented 3 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.