本文介绍了获取RInside示例以使用额外的链接器选项 - 框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了RInside的例子来运行和工作,但我不得不手动添加链接器选项:
-F / Library / Frameworks / R.framework / .. -framework R在Mac Snow Leopard 10.6.8上使用Xcode 3.x)。它有效,但我不知道为什么。任何人都可以说这些选项
实际上做了什么?我无法在此列表中找到它:



以下是原始代码:

  #include< RInside.h> //通过RInside为嵌入式R 

int main(int argc,char * argv [])
{
RInside R(argc,argv); //创建嵌入式R实例
R [txt] =Hello,world!\\\
; //将一个char *(字符串)赋给'txt'
R.parseEvalQ(cat(txt)); // eval init字符串,忽略任何返回
exit(0);
}

这是我在NetBeans中看到的链接器调用:


$ b g ++ -o dist / Debug / GNU-MacOSX / callingrproject build / Debug / GNU-MacOSX / main.o - L / Library / Frameworks / R.framework / Resources / lib -L /Library/Frameworks/R.framework/Resources/library/Rcpp/lib -L ​​/ Library / Frameworks / R.framework / Resources / library / RInside / lib -L ​​/ Library / Frameworks / R.framework / Libraries -L / Library /Frameworks/R.framework/Resources/lib -L ​​/ Library / Frameworks / R.framework / Resources / library -L / Library / Frameworks / R.framework / Resources / modules -lRcpp -lRInside -lRlapack -lRblas -F / Library /Frameworks/R.framework/ .. -framework R



最后一部分是我必须手动添加的内容。没有这些,我得到了这两个连接错误:

pre $ 未定义的符号:
_Rf_mkString,引用自:
main.o中的Rcpp :: wrap(char const *)
_R_NilValue,引用自:
main.o中的Rcpp :: wrap(char const *)


解决方案

框架或多或少地是Mac打包应用程序的方式。这些应用程序可能包含我们想要使用的代码+头文件+库。该行

  -F / Library / Frameworks / R.framework / .. 

说,查看文件夹 / Library / Frameworks 获取指定的任何框架,和

  -framework R 

表示,在'框架'目录集中寻找文件夹 R.framework



请注意, -framework R 参数实际上由 ld 处理,而不是 gcc / clang ,因此您可以在 man ld 中找到更多信息。另一方面, -F 参数 gcc / <$处理C $ C>铛。它们一起允许您的编译器和链接器查找所需的头文件和库。

特别是,在Mac上,它们位于(默认情况下)为 /Library/Frameworks/R.framework/Headers /Library/Frameworks/R.framework/Libraries - 这些是通过设置适当的框架标记搜索的目录。



有关的更多信息,请点击这里以及。

I got the RInside example to run and work but I had to manually add the linker option:"-F/Library/Frameworks/R.framework/.. -framework R" at the end for g++ (on Mac Snow Leopard 10.6.8 with Xcode 3.x). It works, but I don't know why. Can anyone say what these optionsactually do ? I could not find it on this list: http://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

Here is the original code:

#include <RInside.h>                    // for the embedded R via RInside

int main(int argc, char *argv[]) 
{
 RInside R(argc, argv);              // create an embedded R instance 
 R["txt"] = "Hello, world!\n";  // assign a char* (string) to 'txt'
 R.parseEvalQ("cat(txt)");           // eval the init string, ignoring any returns
 exit(0);
}

Here is the linker call as I saw it in NetBeans:

g++ -o dist/Debug/GNU-MacOSX/callingrproject build/Debug/GNU-MacOSX/main.o - L/Library/Frameworks/R.framework/Resources/lib -L/Library/Frameworks/R.framework/Resources/library/Rcpp/lib -L/Library/Frameworks/R.framework/Resources/library/RInside/lib -L/Library/Frameworks/R.framework/Libraries -L/Library/Frameworks/R.framework/Resources/lib -L/Library/Frameworks/R.framework/Resources/library -L/Library/Frameworks/R.framework/Resources/modules -lRcpp -lRInside -lRlapack -lRblas -F/Library/Frameworks/R.framework/.. -framework R

The last part is what I had to add manually. Without that I got these two linkage errors:

Undefined symbols:
 "_Rf_mkString", referenced from:
   Rcpp::wrap(char const*)in main.o
 "_R_NilValue", referenced from:
   Rcpp::wrap(char const*)in main.o
解决方案

Frameworks are, more or less, a Mac way of packaging applications. These applications might contain code + headers + libraries we want to use. The line

-F/Library/Frameworks/R.framework/..

says, "look in the folder /Library/Frameworks for any frameworks that get specified", and

-framework R

says, "look for the folder R.framework in the set of 'frameworks' directories".

Note that the -framework R argument is actually handled by ld, not gcc/clang, so you would find more information in man ld. The -F argument, on the other hand, is handled by gcc/clang. Together, they allow your compiler and linker to find headers and libraries needed.

In particular, on Mac, they are located (by default) as /Library/Frameworks/R.framework/Headers and /Library/Frameworks/R.framework/Libraries -- these are the directories scoured by setting the appropriate framework flags.

More information is available here for the -F argument and for the -framework argument.

这篇关于获取RInside示例以使用额外的链接器选项 - 框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 20:16