gpt4 book ai didi

c++ - 无法运行C++代码(主要是缺少文件(.h))

转载 作者:行者123 更新时间:2023-12-02 10:33:02 25 4
gpt4 key购买 nike

我已经在R 3.6.3和最近的R 4.0中尝试了以下方法。
运行Mac OSX Catalina。我有版本Xcode 11.4.1并做了xcode-select --install以确保我具有命令行工具。

当必须从Rstudio中的源代码编译R包时,出现错误config.h
找不到。尝试Rcpp时遇到类似错误(找不到某些.h,例如math.h)。

如果有人可以解决,请告诉我。谢谢我在这个问题上搜索了很多
但一直无法解决。

* installing *source* package ‘pkgbuild’ ...
** package ‘pkgbuild’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** 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 (pkgbuild)
* installing *source* package ‘rlang’ ...
** package ‘rlang’ successfully unpacked and MD5 sums checked
** using staged installation
** libs
clang -mmacosx-version-min=10.13 -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -I./lib/ -I/usr/local/include -fPIC -Wall -g -O2 -c capture.c -o capture.o
In file included from capture.c:1:
In file included from /Library/Frameworks/R.framework/Resources/include/Rinternals.h:44:
In file included from /Library/Frameworks/R.framework/Resources/include/R_ext/Arith.h:41:
In file included from /usr/local/include/math.h:8:
In file included from /usr/local/include/features.h:10:
/usr/local/include/forwards.h:10:10: fatal error: 'config.h' file not found
#include "config.h"
^~~~~~~~~~
1 error generated.
make: *** [capture.o] Error 1
ERROR: compilation failed for package ‘rlang’
* removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rlang’
Warning in install.packages :
installation of package ‘rlang’ had non-zero exit status

最佳答案

我在致力于R Developers的邮件列表上张贴了类似的内容。经过一番讨论,很明显在/ usr / local / include和/ usr / local / library中存在冲突的头文件。选择这些* .h文件,而不是与R相关的文件。

一个有效的解决方案是创建一个名为〜/ .R的目录,然后在该目录中包含一个带有以下一行的Makevars文件:

CPPFLAGS = -isysroot /库/开发人员/CommandLineTools/SDKs/MacOSX.sdk

第二种解决方案是重命名/ usr / local / library和/ usr / local / include使其命名为,以便在尝试从C++源代码编译或使用软件包Rcpp时R无法使用这些文件。

希望这些解决方案在遇到类似问题时能对其他人有所帮助。

关于c++ - 无法运行C++代码(主要是缺少文件(.h)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61565670/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com