我收到一個鏈接器錯誤,說當我嘗試在CLion中編譯Rcpp文件時找不到符號。該文件使用sourceCpp命令在R中編譯工作正常。這表明我在CLion中的配置有些不正確。我試着按照thread的建議,包括從源代碼編譯Rcpp。ld找不到x86_64架構的Rcpp符號
在CLion IDE中使用這種編譯並使用調試工具會很好。如果任何人都可以指導我做一個指導,以獲得這個工作或提供額外的,它將不勝感激。
一個簡單的例子文件如下:
#include <Rcpp.h>
// Enable C++11 via this plugin (Rcpp 0.10.3 or later)
// [[Rcpp::plugins(cpp11)]]
using namespace Rcpp;
// [[Rcpp::export]]
double sumC(NumericVector x) {
int n = x.size();
double total = 0;
for(int i = 0; i < n; ++i) {
total += x[i];
}
return total;
}
int main() {
NumericVector v(2);
v[0] = 1;
v[1] = 2;
std::cout << sumC(v);
return 0;
}
而且是的CMakeLists.txt
cmake_minimum_required(VERSION 3.3)
project(RcppTest)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(RcppTest ${SOURCE_FILES})
include_directories(/Library/Frameworks/R.framework/Headers)
include_directories(/Library/Frameworks/R.framework/Resources/library/Rcpp/include)
由鏈接器產生的錯誤信息是:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/username/Library/Caches/clion11/cmake/generated/60a4b8d1/60a4b8d1/Debug --target RcppTest -- -j 8
Scanning dependencies of target RcppTest
[ 50%] Building CXX object CMakeFiles/RcppTest.dir/main.cpp.o
[100%] Linking CXX executable RcppTest
Undefined symbols for architecture x86_64:
"_REprintf", referenced from:
Rcpp::Rstreambuf<false>::xsputn(char const*, long) in main.cpp.o
Rcpp::Rstreambuf<false>::overflow(int) in main.cpp.o
"_R_FlushConsole", referenced from:
Rcpp::Rstreambuf<false>::sync() in main.cpp.o
Rcpp::Rstreambuf<true>::sync() in main.cpp.o
"_R_GetCCallable", referenced from:
dataptr(SEXPREC*) in main.cpp.o
"_R_NilValue", referenced from:
Rcpp::PreserveStorage<Rcpp::Vector<14, Rcpp::PreserveStorage> >::PreserveStorage() in main.cpp.o
Rcpp::PreserveStorage<Rcpp::Vector<14, Rcpp::PreserveStorage> >::~PreserveStorage() in main.cpp.o
Rcpp::Rcpp_ReleaseObject(SEXPREC*) in main.cpp.o
Rcpp::Rcpp_PreserveObject(SEXPREC*) in main.cpp.o
"_R_PreserveObject", referenced from:
Rcpp::Rcpp_PreserveObject(SEXPREC*) in main.cpp.o
"_R_ReleaseObject", referenced from:
Rcpp::Rcpp_ReleaseObject(SEXPREC*) in main.cpp.o
"_Rf_allocVector", referenced from:
Rcpp::Vector<14, Rcpp::PreserveStorage>::Vector(int const&) in main.cpp.o
"_Rf_isNull", referenced from:
Rcpp::Rcpp_ReplaceObject(SEXPREC*, SEXPREC*) in main.cpp.o
"_Rf_xlength", referenced from:
Rcpp::Vector<14, Rcpp::PreserveStorage>::size() const in main.cpp.o
void Rcpp::internal::r_init_vector<14>(SEXPREC*) in main.cpp.o
"_Rprintf", referenced from:
Rcpp::Rstreambuf<true>::xsputn(char const*, long) in main.cpp.o
Rcpp::Rstreambuf<true>::overflow(int) in main.cpp.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[3]: *** [RcppTest] Error 1
make[2]: *** [CMakeFiles/RcppTest.dir/all] Error 2
make[1]: *** [CMakeFiles/RcppTest.dir/rule] Error 2
make: *** [RcppTest] Error 2
使用操作系統X 10.10.5,R版本3.2.2(2015-08-14),Apple LLVM版本6.1.0(clang-602.0.53),Rcpp 0.12.0
CMake不被我們支持。 _如果它打破,你會保留件。我們的Makefiles的工作,看看他們做什麼,如果必須的話,帶着東西。 –
錯誤意味着你沒有鏈接到'libR'。 –