2013-03-18 69 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目錄(當它不應該)。