2013-03-18 72 views
2

我想开始使用Rccp,并决定使用Eclipse作为开发环境,因为我已经使用了StatEt for R.我很难获得一个简单的程序来编译和运行,并会感谢一些帮助!在Mac OS X上的Rcpp + Eclipse

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

我是C++的新手,所以我非常感谢有关如何继续的一些指导。

-Krishna

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' 
+0

我没有看到您获得指示安装XCode的步骤。你究竟有多少新手? – 2013-03-19 00:49:25

+0

我需要一个C++编译器,所以我决定通过安装命令行工具从XCode使用g ++。我没有用C++编程一段时间,也从来没有用Mac编写过。 – user1748083 2013-03-19 01:06:32

+0

看来,这不是一个Rcpp问题,更多的是一个RInside问题。您能否按照博客文章中的说明所述使用Rcpp构建软件包?其次,eclipse找到你的C++路径似乎有问题。你可以使用Eclipse创建并运行常规的C++项目(不是R)吗?如果是这样,你是否通过创建C++项目来启动博客文章中的步骤? – 2013-03-19 03:12:09

回答

2

总之,我所面临的问题是,包括文件Rcpp与与std中的名称相同的名称存在冲突。特别是,string.h from Rcpp被包含在string.hstd是正确的选择,并且,据我所知,这是由于在默认路径之前搜索通过-I指令指定的路径的事实。

我尝试了很多不同的方法来解决这个问题,包括删除并重新安装XCode和相关的命令行工具,以及使用macports安装另一个g ++编译器。这些都没有解决这个问题。然后,我使用-idirafter指令而不是-I指令作为Rcpp和R的包含文件的搜索路径。我从gcc include order broken?得到了此提示。这是因为这些目录现在在缺省路径之后被搜索。这排除了(至少到目前为止)string.hstdstring.hRcpp发生冲突的可能性。

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

感谢大家的建议。

2

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

  1. 得到所有你需要的安装RCPP。 OS X方面应记录在Simon维护的相关页面上。如果你有这些工具,并且安装了Rcpp,那么你应该可以执行cppFunction('double nPi(int x) { return x*M_PI; }')这是使用Rcpp提供的函数来创建可访问的C++函数,因为nPi() - 和​​应该返回一个值。

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

所以我会在1工作,看看我得到了整理出来的第一,然后才轮到2.

+0

你好德克: 谢谢你的快速反应,并感谢伟大的包!事实上,我已经覆盖了1个,因为我已经安装了Rcpp并尝试了一些例子,还有上面的例子。我想获得一个可用的Eclipse环境,以使用Rcpp进行开发,因此是一个问题。 – user1748083 2013-03-19 01:11:30

+0

很高兴听到它的工作。我无法帮助Eclipse,对不起。 – 2013-03-19 01:16:15

+1

好的,所以我尝试了许多不同的方法来解决这个问题,包括删除和重新安装XCode和相关的命令行工具,以及使用macports安装另一个g ++编译器。这些都没有解决这个问题。然后,我使用-idirafter指令而不是-I指令来包含Rcpp和R的包含文件的搜索路径。这是因为这些目录是在缺省路径后搜索的。这至少排除了(至少到目前为止)从'std'和''Rcpp'中的'string.h'发生冲突的可能性。感谢大家的建议。 – user1748083 2013-03-19 22:00:55

1

您只需去除包括

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

,因为它是:

  • 不必要的,因为所有的R进口的形式<Rcpp/XXX>
  • 原因这个问题,因为编译器会寻找string.hRcpp目录(当它不应该)。