2

我正在尝试开始使用 Rccp 并决定使用 Eclipse 作为开发环境,因为我已经将 StatEt 用于 R。我什至无法编译和运行一个简单的程序,希望能得到一些帮助!

简要地说,我尝试按照博客上的说明进行操作:http : //blog.fellstat.com/?p=170 完全用于设置 Rcpp、RInside 和 Eclipse,以及示例程序。我在 Mountain Lion 上运行,并使用 XCode 中的命令行选项安装了 g++。我想我已经忠实地遵循了博客中的所有步骤,但无法编译程序。我认为问题在于包含头文件的方式,如下面的输出片段所示。据我所知,第 52 行/usr/include/c++/4.2.1/cstring是一个包含语句,<string.h>编译器包含Rccp/include/string.h而不是前面在包含路径上找到的string.hfrom 。std

我是 C++ 的新手,所以我非常感谢一些关于如何进行的指示。

-克里希纳

16:22:38 **** Incremental Build of configuration Debug for project MyTestRCppPackage ****
Info: Internal Builder is used for build
g++ -DINSIDE -I/Library/Frameworks/R.framework/Versions/2.15/Resources/include -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/RInside/include -O0 -g3 -Wall -c -fmessage-length=0 -arch x86_64 -v -o src/main.o ../src/main.cpp 
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~182/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
 /usr/llvm-gcc-4.2/bin/../libexec/gcc/i686-apple-darwin11/4.2.1/cc1plus -quiet -v -I/Library/Frameworks/R.framework/Versions/2.15/Resources/include -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp -I/Library/Frameworks/R.framework/Versions/2.15/Resources/library/RInside/include -imultilib x86_64 -iprefix /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/ -dD -D__DYNAMIC__ -DINSIDE ../src/main.cpp -fPIC -quiet -dumpbase main.cpp -mmacosx-version-min=10.8.3 -m64 -mtune=core2 -auxbase-strip src/main.o -g3 -O0 -Wall -version -fmessage-length=0 -D__private_extern__=extern -o /var/folders/hc/vqp48jt56_v332kc3dqyf5780000gn/T//ccqdmOKI.s
ignoring nonexistent directory "/usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include"
ignoring nonexistent directory "/usr/include/c++/4.2.1/i686-apple-darwin11/x86_64"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/../../../../i686-apple-darwin11/include"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Frameworks/R.framework/Versions/2.15/Resources/include
 /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include
 /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp
 /Library/Frameworks/R.framework/Versions/2.15/Resources/library/RInside/include
 /usr/llvm-gcc-4.2/bin/../lib/gcc/i686-apple-darwin11/4.2.1/include
 /usr/include/c++/4.2.1
 /usr/include/c++/4.2.1/backward
 /usr/local/include
 /Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1/include
 /usr/include
 /System/Library/Frameworks (framework directory)
 /Library/Frameworks (framework directory)
End of search list.
GNU C++ version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) (i686-apple-darwin11)
    compiled by GNU C version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00).
GGC heuristics: --param ggc-min-expand=150 --param ggc-min-heapsize=65536
Compiler executable checksum: b37fef824b01c0a99fb2679acf3b04f1
In file included from /usr/include/c++/4.2.1/cstring:52,
                 from /usr/include/c++/4.2.1/bits/stl_algobase.h:66,
                 from /usr/include/c++/4.2.1/memory:53,
                 from /usr/include/c++/4.2.1/tr1/hashtable:56,
                 from /usr/include/c++/4.2.1/tr1/unordered_map:37,
                 from /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/platform/compiler.h:158,
                 from /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/RcppCommon.h:26,
                 from /Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp.h:27,
                 from ../src/main.cpp:8:
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:52: error: 'internal' has not been declared
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:52: error: typedef name may not be a nested-name-specifier
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:52: error: expected ';' before '<' token
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:65: error: expected `)' before 'charsxp'
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:70: error: expected ',' or '...' before '&' token
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:75: error: expected unqualified-id before '&' token
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:75: error: expected ',' or '...' before '&' token
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:75: error: 'Rcpp::String::String()' cannot be overloaded
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:55: error: with 'Rcpp::String::String()'
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:85: error: 'Rcpp::String::String(int)' cannot be overloaded
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:70: error: with 'Rcpp::String::String(int)'
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:88: error: expected `)' before 'x'
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/string.h:89: error: expected `)' before 'x'
4

3 回答 3

2

这里有两个完全不同的问题:

  1. 获取安装 Rcpp 所需的一切。OS X 方面应记录在 Simon 维护的相关页面上。如果您拥有这些工具并安装了 Rcpp,那么您应该能够cppFunction('double nPi(int x) { return x*M_PI; }')使用 Rcpp 提供的函数来创建一个可供您访问的可调用 C++ 函数,nPi()并且nPi(2)应该返回一个值。

  2. 您选择的 IDE 及其设置。这与 1. 没有什么关系,除了要求它工作之外。

所以我会在 1 上工作,看看我是否先解决了这个问题,然后才转向 2。

于 2013-03-19T01:06:36.607 回答
2

总而言之,我面临的问题是包含Rcpp与其中相同名称的文件std发生冲突。特别是,string.hfromRcpp被包含在string.hfromstd是正确选择的地方,据我所知,这是由于-I在默认路径之前搜索通过指令指定的路径。

我尝试了许多不同的替代方案来解决这个问题,包括删除和重新安装 XCode 和相关的命令行工具,以及使用 macports 安装另一个 g++ 编译器。这些都没有解决问题。然后,我使用-idirafter指令而不是-I指令来搜索 Rcpp 和 R 的包含文件的路径。我从gcc 中得到了这个提示包含顺序损坏?. 这很有效,因为现在在默认路径之后搜索这些目录。这排除了(至少到目前为止!)string.hfromstdstring.hfromRcpp发生冲突的可能性。

要使http://blog.fellstat.com/?p=170的第 5 步工作,我必须在文件中设置-idirafter路径 。PKG_CPPFLAGSMakevars

感谢大家的建议。

于 2013-03-20T18:51:01.577 回答
1

您只需删除包含

/Library/Frameworks/R.framework/Resources/library/Rcpp/include/Rcpp

因为它是:

  • 不必要的,因为所有 R 进口都是形式<Rcpp/XXX>
  • 导致此问题,因为编译器string.hRcpp目录中查找(当它不应该时)。
于 2013-06-11T21:47:00.137 回答