OSX El CapitainでC++ソースファイルからdylibファイルを作成してRcpp経由でRに読み込もうとしています。ここで私が作成したものを著しく単純化した例です。g ++ Rcpp osx上のアーキテクチャx86_64の未定義のシンボル
//test.cpp
#include <Rcpp.h>
RcppExport SEXP dosum(SEXP _a, SEXP _b){
double a = Rcpp::as<double>(_a);
double b = Rcpp::as<double>(_b);
return Rcpp::wrap(a+b);
}
私は大学で私に利用できるLinuxサーバー上で次のMakefileを使って/リンクをコンパイルすると、
CC=g++
# note the use of c++14, used to use c++11
all: test
test :
${CC} -DNDEBUG \
-I. \
-I/usr/share/R/include \
-I/server/linux/lib/R/3.0/x86_64/site-library/Rcpp/include \
-I/usr/share/Rcpp_0.12.3/include \
-fpic -O3 -pipe \
-std=c++1y \
-c test.cpp
${CC} -shared -o test.so test.o
clean:
@find . \(-name "*.o" -o -name "*.so" \) -exec rm {} \;
私は希望のtest.so
ファイルを入手してください。これをdyn.load('test.so')
でRセッション中に読み込むことができます。ロードされたら、dosum()
をdosum(x,y)
経由で使用することができます。すばらしいです。
私の個人的なMacでOSX El Capitainと全く同じことをしたいと思います。私は
あるg++ \
-I. \
-I/usr/share/R/include \
-I/usr/local/include/Rcpp/Rcpp_0.12.5/inst/include \
-fPIC \
-c temp.cpp
g++ -dynamiclib *.o -o temp.dylib
Undefined symbols for architecture x86_64:
"_REprintf", referenced from:
Rcpp::Rstreambuf<false>::xsputn(char const*, long) in temp.o
Rcpp::Rstreambuf<false>::overflow(int) in temp.o
"_R_FlushConsole", referenced from:
Rcpp::Rstreambuf<true>::sync() in temp.o
Rcpp::Rstreambuf<false>::sync() in temp.o
"_R_GetCCallable", referenced from:
dataptr(SEXPREC*) in temp.o
"_R_NilValue", referenced from:
Rcpp::Rcpp_protect(SEXPREC*) in temp.o
Rcpp::Shield<SEXPREC*>::~Shield() in temp.o
"_Rf_allocVector", referenced from:
SEXPREC* Rcpp::internal::primitive_wrap__impl__cast<double>(double const&, Rcpp::traits::integral_constant<bool, false>) in temp.o
"_Rf_coerceVector", referenced from:
SEXPREC* Rcpp::internal::basic_cast<14>(SEXPREC*) in temp.o
"_Rf_length", referenced from:
double Rcpp::internal::primitive_as<double>(SEXPREC*) in temp.o
"_Rf_protect", referenced from:
Rcpp::Rcpp_protect(SEXPREC*) in temp.o
"_Rf_unprotect", referenced from:
Rcpp::Shield<SEXPREC*>::~Shield() in temp.o
"_Rprintf", referenced from:
Rcpp::Rstreambuf<true>::xsputn(char const*, long) in temp.o
Rcpp::Rstreambuf<true>::overflow(int) in temp.o
"_TYPEOF", referenced from:
SEXPREC* Rcpp::r_cast<14>(SEXPREC*) in temp.o
SEXPREC* Rcpp::internal::basic_cast<14>(SEXPREC*) in temp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [temp] Error 1
、物事が文字化けして取得しているように見える、私はこのMakefileを実行すると
CC=g++
all: temp
temp:
${CC} \
-I. \
-I/usr/share/R/include \
-I/usr/local/include/Rcpp/Rcpp_0.12.5/inst/include \
-fPIC \
-c temp.cpp
${CC} -dynamiclib *.o -o temp.dylib
clean:
@find . \(-name "*.o" -o -name "*.dylib" \) -exec rm {} \;
が、私は以下を取得し、Makefileの多くのバリエーションを試してみましたが、現在は使用しています問題の変数の前にアンダースコアが追加されています。私は間違って何をしていますか?私は-fpic
,-std=XXX
のような様々なフラグを追加/削除しようとしました。
私は関連する質問を見つけましたが、元のポスターが最初にRcppを使用する方法を混乱させるケースと思われます。ここでは、LinuxでできることをMacでやりたいだけです。 MacのヘッダファイルとLinuxのヘッダファイルとの間に基本的な違いがあるとは思えませんが、詳細はまだ確認していません。
FWIW、私は、限り、彼らはRcpp(例えば、簡単なcout << "hello world" <<endl;
機能)を使用しないように、多分私のRcppのインストールが何らかの形で台無しにされた私のMac上の同じアプローチを使用してdylibsを作成することができます。
はい、私はcppFunctionを使用することができることを知っていたが、私の実際のコードは、数千行です多くの異なるファイルに長い分割。 Fortranルーチンも含まれています。その場合でもcppFunctionを使用することは可能ですか?そして、プログラムを実行するたびにコードを再コンパイルする必要があるのは当てはまりませんか? – xbot
要するに、パッケージをビルドします。間違ってしまうのは簡単すぎるので、Makefileは決して望みません。あなたがここでしたように。 –