简体   繁体   English

在 Windows 上使用静脉和 OMNET++ 配置 RInside

[英]Configure RInside with Veins and OMNET++ on Windows

I have been trying to configure RInside with Veins and OMNET++, but finding some issues.我一直在尝试使用 Veins 和 OMNET++ 配置 RInside,但发现了一些问题。

After going through the discussion in Is it possible to use RInside in omnet++/Veins project to benefit from rich R features and How to set up Eclipse + StatET + Rcpp on Windows , I created a new project (shared type) in omnet++ and tried to configure RInside it.在讨论了是否可以在 omnet++/Veins 项目中使用 RInside 以受益于丰富的 R 功能以及如何在 Windows 上设置 Eclipse + StatET + Rcpp 中的讨论后,我在 omnet++ 中创建了一个新项目(共享类型)并尝试配置R里面。 I am experiencing some errors ( "undefined reference to RInside::operator[]", "undefined reference to RInside::parseEvalQ") .我遇到了一些错误( "undefined reference to RInside::operator[]", "undefined reference to RInside::parseEvalQ")

I know that this is a linking error.我知道这是一个链接错误。 I am fairly new to C++ configurations and eclipse based IDEs so struggling to figure out what's wrong.我对 C++ 配置和基于 Eclipse 的 IDE 还很陌生,所以很难找出问题所在。 I am attaching the screenshots of the configurations as well.我还附上了配置的屏幕截图。 I would really appreciate if someone can help.如果有人可以提供帮助,我将不胜感激。

错误 配置 在此处输入图片说明 在此处输入图片说明

Update (after successfully building RInside and making sure that the tool chain is right)更新(在成功构建 RInside 并确保工具链正确后)

Here is the makefrag file这是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

I gave integrating RInside and Veins (version 5 alpha 1) a quick try and can report success.我快速尝试了集成 RInside 和 Veins(版本 5 alpha 1),并且可以报告成功。

I installed RInside by running R and executing install.packages('RInside') .我通过运行 R 并执行install.packages('RInside')来安装 RInside。

I then amended the following lines (mostly copied from the RInside examples GNUMakefile) to the Veins src/makefrag file:然后我将以下几行(主要从 RInside 示例 GNUMakefile 复制)修改为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)

After that, I could use R inside Veins.之后,我可以在 Veins 中使用 R。 I tried this by copying code from RInside rinside_sample0.cpp to Veins BaseConnectionManager.cc as follows:我通过将代码从 RInside rinside_sample0.cpp复制到 Veins rinside_sample0.cpp进行了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";

Compiling Veins ( ./configure followed by make ) and running the tutorial example ( cd examples/veins followed by ./run -u Cmdenv ) produced the desired output:编译 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...

(Note the Hello, world! output during initialization of the simulation.) (注意模拟初始化期间的Hello, world!输出。)

Building on Windows will likely mean copying lines from the RInside examples Makefile.win file instead.在 Windows 上构建可能意味着从 RInside 示例 Makefile.win 文件中复制行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM