告诉RStudio不要忽略在Makevars中使用clang的指示。

huangapple go评论111阅读模式
英文:

How to I tell RStudio not to ignore the indication to use clang in Makevars?

问题

以下是翻译后的内容:

  1. 我在 `Makefile` 中有这个:

PKG_CC = clang-15
PKG_CXX = clang++-15
PKG_CXXFLAGS = -g -O0 -fopenmp
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
CXX_STD = CXX11
PKG_CPPFLAGS = -UDEBUG -g

  1. 当我运行 `devtools::install()` 时,我看到 `g++ -std=gnu++11 -I"/usr/share/R/include"...` 而不是我期望的 `clang...`,因为下一个测试起作用了:
  2. ```R
  3. > pkgbuild::check_build_tools(debug = TRUE)
  4. 尝试编译一个简单的 C 文件
  5. 运行 /usr/lib/R/bin/R CMD SHLIB foo.c
  6. 使用 C 编译器:‘Ubuntu clang version 15.0.7’
  7. clang-15 -I"/usr/share/R/include" -DNDEBUG -fpic -g -O2 -ffile-prefix-map=/build/r-base-JhpCKt/r-base-4.3.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c foo.c -o foo.o
  8. clang-15 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o foo.so foo.o -L/usr/lib/R/lib -lR
  9. 你的系统已准备好构建软件包!

到目前为止,我删除了 .Rproj.user 并尝试了

  1. devtools::clean_dll()
  2. devtools::document()
  3. devtools::install()
  1. <details>
  2. <summary>英文:</summary>
  3. I have this in `Makefile`

PKG_CC = clang-15
PKG_CXX = clang++-15
PKG_CXXFLAGS = -g -O0 -fopenmp
PKG_LIBS = $(SHLIB_OPENMP_CXXFLAGS)
CXX_STD = CXX11
PKG_CPPFLAGS = -UDEBUG -g

  1. When I run `devtools::install()`, I see `g++ -std=gnu++11 -I&quot;/usr/share/R/include&quot;...` instead of `clang...`, which I expect because the next test worked:
  2. ```R
  3. &gt; pkgbuild::check_build_tools(debug = TRUE)
  4. Trying to compile a simple C file
  5. Running /usr/lib/R/bin/R CMD SHLIB foo.c
  6. using C compiler: ‘Ubuntu clang version 15.0.7’
  7. clang-15 -I&quot;/usr/share/R/include&quot; -DNDEBUG -fpic -g -O2 -ffile-prefix-map=/build/r-base-JhpCKt/r-base-4.3.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c foo.c -o foo.o
  8. clang-15 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o foo.so foo.o -L/usr/lib/R/lib -lR
  9. Your system is ready to build packages!

So far I deleted .Rproj.user and tried

  1. devtools::clean_dll()
  2. devtools::document()
  3. devtools::install()

答案1

得分: 3

以下是您要翻译的内容:

您可以忽略这里的所有devtools调用,以及所有对RStudio的引用:这些只是额外的层。_一切_最终都会调用R CMD INSTALL,因此您可以直接使用它。

简而言之,您的文件可能具有错误的变量。以下是一个最小的示例(作为我用来在gccclang之间切换的实际子集)

CLANGVER=-15
CLANGLIB=-stdlib=libc++
CXX=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
CXX11=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
CXX14=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
CXX17=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
CXX20=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
CC=$(CCACHE) clang$(CLANGVER)
SHLIB_CXXLD=clang++$(CLANGVER) $(CLANGLIB)
CXXFLAGS=-Wall -O3 -pedantic
CXX11FLAGS=-Wall -O3 -pedantic
CXX14FLAGS=-Wall -O3 -pedantic
CXX17FLAGS=-Wall -O3 -pedantic
CXX20FLAGS=-Wall -O3 -pedantic

我使用CLANGVER,因为Ubuntu通常会给我选择,而我使用VER来表示gcc。通常设置CCACHE(为ccache),但您也可以在没有它的情况下使用,如下所示在包的完整日志中:

edd@rob:~/git/rcppexamples(master)$ ./cleanup; install.r # install.r wraps R CMD INSTALL

  • installing source package found in current working directory ...
  • installing source package ‘RcppExamples’ ...
    ** using staged installation
    ** libs
    using C++ compiler: ‘Ubuntu clang version 15.0.7’
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c DataFrameExample.cpp -o DataFrameExample.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c DateExample.cpp -o DateExample.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c FactorExample.cpp -o FactorExample.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c ListExample.cpp -o ListExample.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c MatrixExample.cpp -o MatrixExample.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c NumericVectorExample.cpp -o NumericVectorExample.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c RNGs.cpp -o RNGs.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c RcppExports.cpp -o RcppExports.o
    clang++-15 -stdlib=libc++ -I"/usr/share/R/include" -DNDEBUG -I''/usr/local/lib/R/site-library/Rcpp/include'' -fpic -Wall -O3 -pedantic -c StringVectorExample.cpp -o StringVectorExample.o
    clang++-15 -stdlib=libc++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o RcppExamples.so DataFrameExample.o DateExample.o FactorExample.o ListExample.o MatrixExample.o NumericVectorExample.o RNGs.o RcppExports.o StringVectorExample.o -L/usr/lib/R/lib -lR
    installing to /usr/local/lib/R/site-library/00LOCK-rcppexamples/00new/RcppExamples/libs
    ** R
    ** inst
    ** byte-compile and prepare package for lazy loading
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded from temporary location
    ** testing if installed package can be loaded from final location
    ** testing if installed package keeps a record of temporary installation path
  • DONE (RcppExamples)
    edd@rob:~/git/rcppexamples(master)$

总之,您使用了错误的变量。它们在我们必须在包和它们的src/Makevars中使用的变量之间存在差异,以及进入~/.R/Makevars的变量。这里没有前缀PKG_,'全局'变量会覆盖R在其自己的$RHOME/etc/Makeconf中的变量。

英文:

You can ignore all devtools invocations here as well as all references to RStudio: these are just added layers. Everything eventually calls R CMD INSTALL so you can this directly.

In short, you file may have the wrong variables. Here is a minimal one (as an actual subset of mine which I use to switch between gcc and clang)

  1. CLANGVER=-15
  2. CLANGLIB=-stdlib=libc++
  3. CXX=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
  4. CXX11=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
  5. CXX14=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
  6. CXX17=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
  7. CXX20=$(CCACHE) clang++$(CLANGVER) $(CLANGLIB)
  8. CC=$(CCACHE) clang$(CLANGVER)
  9. SHLIB_CXXLD=clang++$(CLANGVER) $(CLANGLIB)
  10. CXXFLAGS=-Wall -O3 -pedantic
  11. CXX11FLAGS=-Wall -O3 -pedantic
  12. CXX14FLAGS=-Wall -O3 -pedantic
  13. CXX17FLAGS=-Wall -O3 -pedantic
  14. CXX20FLAGS=-Wall -O3 -pedantic

I use CLANGVER as Ubuntu usually gives me a choice, and I use VER for gcc. CCACHE is usually set (to ccache) but you can use it without it too as shown in the full log from a package here:

  1. edd@rob:~/git/rcppexamples(master)$ ./cleanup; install.r # install.r wraps R CMD INSTALL
  2. * installing *source* package found in current working directory ...
  3. * installing *source* package RcppExamples ...
  4. ** using staged installation
  5. ** libs
  6. using C++ compiler: Ubuntu clang version 15.0.7
  7. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c DataFrameExample.cpp -o DataFrameExample.o
  8. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c DateExample.cpp -o DateExample.o
  9. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c FactorExample.cpp -o FactorExample.o
  10. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c ListExample.cpp -o ListExample.o
  11. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c MatrixExample.cpp -o MatrixExample.o
  12. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c NumericVectorExample.cpp -o NumericVectorExample.o
  13. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c RNGs.cpp -o RNGs.o
  14. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c RcppExports.cpp -o RcppExports.o
  15. clang++-15 -stdlib=libc++ -I&quot;/usr/share/R/include&quot; -DNDEBUG -I&#39;/usr/local/lib/R/site-library/Rcpp/include&#39; -fpic -Wall -O3 -pedantic -c StringVectorExample.cpp -o StringVectorExample.o
  16. clang++-15 -stdlib=libc++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o RcppExamples.so DataFrameExample.o DateExample.o FactorExample.o ListExample.o MatrixExample.o NumericVectorExample.o RNGs.o RcppExports.o StringVectorExample.o -L/usr/lib/R/lib -lR
  17. installing to /usr/local/lib/R/site-library/00LOCK-rcppexamples/00new/RcppExamples/libs
  18. ** R
  19. ** inst
  20. ** byte-compile and prepare package for lazy loading
  21. ** help
  22. *** installing help indices
  23. ** building package indices
  24. ** testing if installed package can be loaded from temporary location
  25. ** testing if installed package can be loaded from final location
  26. ** testing if installed package keeps a record of temporary installation path
  27. * DONE (RcppExamples)
  28. edd@rob:~/git/rcppexamples(master)$

So in short you used the wrong variables. They differ between what we have to use in packages and their src/Makevars and what goes into ~/.R/Makevars. No prefix PKG_ here, the 'global' one overrides what R has in its own $RHOME/etc/Makeconf.

huangapple
  • 本文由 发表于 2023年5月22日 00:03:12
  • 转载请务必保留本文链接:https://go.coder-hub.com/76300775.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定