【问题标题】:Configure RInside with Veins and OMNET++ on Windows在 Windows 上使用 Veins 和 OMNET++ 配置 RInside
【发布时间】:2019-03-13 12:10:41
【问题描述】:

我一直在尝试使用 Veins 和 OMNET++ 配置 RInside,但发现了一些问题。

经过Is it possible to use RInside in omnet++/Veins project to benefit from rich R featuresHow to set up Eclipse + StatET + Rcpp on Windows的讨论后,我在omnet++中新建了一个项目(共享类型),并尝试配置RInside。我遇到了一些错误 ("undefined reference to RInside::operator[]", "undefined reference to RInside::parseEvalQ").

我知道这是一个链接错误。我对 C++ 配置和基于 Eclipse 的 IDE 相当陌生,因此很难找出问题所在。我还附上了配置的屏幕截图。如果有人可以提供帮助,我将不胜感激。

更新(在成功构建 RInside 并确保工具链正确之后)

这是makefrag文件

#
# on windows we have to link with the ws2_32 (winsock2) library as it is no longer added to the omnetpp system libraries by default (as of OMNeT++ 5.1)
# copied from INET Framework (inet-3.6.0) makefrag
#
ifeq ($(PLATFORM),win32.x86_64)
  LIBS += -lws2_32
  DEFINES += -DINET_EXPORT
  ENABLE_AUTO_IMPORT=-Wl,--enable-auto-import
  LDFLAGS := $(filter-out $(ENABLE_AUTO_IMPORT), $(LDFLAGS))

  R_HOME := $(shell R RHOME | sed -e "s|\\\\|\/|g")
  R_ARCH := --arch $(shell echo 'cat(.Platform$$r_arch)' | R --vanilla --slave)
  sources := $(wildcard *.cpp)
  programs := $(sources:.cpp=)

  ## include headers and libraries for R
  RCPPFLAGS := $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config --cppflags)
  RLDFLAGS := $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config --ldflags)
  RBLAS := $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config BLAS_LIBS)
  RLAPACK := $(shell $(R_HOME)/bin/R $(R_ARCH) CMD config LAPACK_LIBS)


  ## include headers and libraries for Rcpp interface classes
  RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)
  RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)


  ## include headers and libraries for RInside embedding classes
  RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)
  RINSIDELIBS := $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R $(R_ARCH) --vanilla --slave)

  #DEFINES += $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CPPFLAGS) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
  #LIBS += $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

endif

【问题讨论】:

  • 我的建议是开始尝试构建(部分)提供的示例来验证您的本地工具链。如果可行,请尝试“移植”到 Eclipse、CMake、... 在过去的某个时候,贡献的 CMakefile 可以工作,但如果 a)它们都在 Windows 上工作,或者 b)它们是最新的,我不这样做。我使用标准的 R 工具...
  • OMNeT++ 模拟传统上是通过 opp_makemake 构建的,它创建 GNU Makefile。调整这些 Makefile 以使用自定义包含路径和库的一种简单方法是使用 makefrag 文件,该文件包含将插入到创建的 Makefile 中的代码片段。尝试构建 Veins,检查在 src/ 中创建的 Makefile,将其与 src/ 中的 makefrag 文件进行比较,并尝试从 RInside 的示例 Makefile 中获取代码,例如,github.com/eddelbuettel/rinside/blob/6699d52/inst/examples/…
  • 感谢德克和克里斯托夫!非常感谢您的建议。我将围绕这些发布我的发现。

标签: omnet++ veins rinside


【解决方案1】:

我快速尝试了集成 RInside 和 Veins(版本 5 alpha 1),可以报告成功。

我通过运行 R 并执行 install.packages('RInside') 来安装 RInside。

然后我将以下几行(主要从 RInside 示例 GNUMakefile 复制)修改为 Veins src/makefrag 文件:

# determine flags for RInside
R_HOME := $(shell R RHOME)
RCPPFLAGS := $(shell $(R_HOME)/bin/R CMD config --cppflags)
RLDFLAGS := $(shell $(R_HOME)/bin/R CMD config --ldflags)
RBLAS := $(shell $(R_HOME)/bin/R CMD config BLAS_LIBS)
RLAPACK := $(shell $(R_HOME)/bin/R CMD config LAPACK_LIBS)
RCPPINCL := $(shell echo 'Rcpp:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RCPPLIBS := $(shell echo 'Rcpp:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)
RINSIDEINCL := $(shell echo 'RInside:::CxxFlags()' | $(R_HOME)/bin/R --vanilla --slave)
RINSIDELIBS := $(shell echo 'RInside:::LdFlags()'  | $(R_HOME)/bin/R --vanilla --slave)

# feed to opp_makemake
DEFINES += $(RCPPFLAGS) $(RCPPINCL) $(RINSIDEINCL) $(shell $(R_HOME)/bin/R CMD config CPPFLAGS) $(shell $(R_HOME)/bin/R CMD config CXXFLAGS)
LIBS += $(RLDFLAGS) $(RRPATH) $(RBLAS) $(RLAPACK) $(RCPPLIBS) $(RINSIDELIBS)

之后,我可以在 Veins 中使用 R。我通过将代码从 RInside rinside_sample0.cpp 复制到 Veins BaseConnectionManager.cc 来尝试此操作,如下所示:

diff --git a/src/veins/base/connectionManager/BaseConnectionManager.cc b/src/veins/base/connectionManager/BaseConnectionManager.cc
index 879e90d244..8e9eba10e8 100644
--- a/src/veins/base/connectionManager/BaseConnectionManager.cc
+++ b/src/veins/base/connectionManager/BaseConnectionManager.cc
@@ -1,3 +1,5 @@
+#include <RInside.h>
+
 #include "veins/base/connectionManager/BaseConnectionManager.h"

 #include "veins/base/connectionManager/NicEntryDebug.h"
@@ -42,6 +44,12 @@ void BaseConnectionManager::initialize(int stage)
     // BaseModule::initialize(stage);

     if (stage == 0) {
+
+        // Hello R!
+        RInside R;
+        R["txt"] = "Hello, world!\n";
+        R.parseEvalQ("cat(txt)");
+
         drawMIR = hasPar("drawMaxIntfDist") ? par("drawMaxIntfDist").boolValue() : false;

         EV_TRACE << "initializing BaseConnectionManager\n";

编译 Veins(./configure 后跟 make)并运行教程示例(cd examples/veins 后跟 ./run -u Cmdenv)产生了所需的输出:

OMNeT++ Discrete Event Simulation  (C) 1992-2018 Andras Varga, OpenSim Ltd.
Version: 5.4.1, build: 180629-5e28390, edition: Academic Public License -- NOT FOR COMMERCIAL USE
See the license for distribution terms and warranty disclaimer

Setting up Cmdenv...

Loading NED files from ../../src/veins:  41
Loading NED files from .:  1
Loading NED files from /Users/sommer/src/veins/examples/veins:  1

Preparing for running configuration General, run #0...
Assigned runID=General-0-20190308-18:16:24-23603
Setting up network "RSUExampleScenario"...
Initializing...
Hello, world!

Running simulation...

(注意模拟初始化期间的Hello, world! 输出。)

在 Windows 上构建可能意味着从 RInside 示例 Makefile.win 文件中复制行。

【讨论】:

  • 非常感谢!我编辑了 makefrag 文件并构建了项目,但最终得到了“make[1]: /bin/R: Command not found”。我在命令行上运行了“R RHOME”命令,并将路径正确地设置为“C:\R-3.5.2\”。仍然无法弄清楚为什么..
  • 我的错 - 我忘了提到我是通过从 RInside 示例 GNUMakefile(用于在 macOS、Linux 等上构建示例的文件)复制来做到这一点的 - 而不是从它的 Makefile.win(用于在 Windows 上构建的文件)
  • 一切顺利!我构建了 Dirk 提到的 RInside 示例,并且效果很好。然后像你一样,我将 Makefile.win 中的相关内容复制到 Veins 中的 makefrag 文件并构建。我仍然收到“/bin/sh: R: command not found”和“make[1]: /bin/R: Command not found”。我认为 "R_HOME := $(shell R RHOME | sed -e "s|\\\\|\/|g")" 行没有正确选择路径。对此有什么想法以及如何纠正它?
  • 您是否可以编辑您的问题以使用您目前在 makefrag 中的内容进行修改?
猜你喜欢
  • 1970-01-01
  • 2018-07-25
  • 1970-01-01
  • 1970-01-01
  • 2012-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多