Rcpp
外部ライブラリを使用するコードでR パッケージをビルドしようとしています。以前、パッケージで外部 C ライブラリを使用する方法について SO に質問したことがあります。私が直面している問題は、次のコード行を含めるとすぐに発生します
y = N_VNew_Serial(3);
エラーが発生しています
sundials_test.o:sundials_test.cpp:(.text+0x2ba): undefined reference to `N_VNew_Serial'
collect2: ld returned 1 exit status
Error in Rcpp::sourceCpp("src/sundials_test.cpp") :
Error occurred building shared library
行でエラーが発生しません
N_Vector y = NULL;
そのため、ライブラリへの接続は正常に機能していると思います。の関数宣言が にあることも確認しました。パッケージコード全体を見る必要がある場合はN_VNewSerial()
、こちらnvector/nvector_serial.h
特定のファイルのコードをRcpp
以下に貼り付けます
#include <Rcpp.h>
// #include <iostream.h>
#include <cvode/cvode.h> /* prototypes for CVODE fcts., consts. */
#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
#include <cvode/cvode_dense.h> /* prototype for CVDense */
#include <sundials/sundials_dense.h> /* definitions DlsMat DENSE_ELEM */
#include <sundials/sundials_types.h> /* definition of type realtype */
using namespace Rcpp;
void InitialConditions (NumericVector x){
N_Vector y = NULL;
// y = N_VNew_Serial(3);
//
// NV_Ith_S(y,0) = 1;
// NV_Ith_S(y,1) = 2;
// NV_Ith_S(y,2) = 3;
}
コードがundefined reference
同じヘッダー ファイル内の 1 つの関数にレポートしているのに、別の関数にはレポートしていない理由がわかりません。このエラーを解決するための助けをいただければ幸いです。
ありがとう!
SN248