【问题标题】:Using RInside in a Qt 5.5.1 app under Windows 7在 Windows 7 下的 Qt 5.5.1 应用程序中使用 RInside
【发布时间】:2016-09-02 18:08:32
【问题描述】:

我目前正在处理一个 Qt 5.5 项目,并希望对我的 R 解释器(我在我的 Windows 7 系统上使用 R 3-3-1)执行一些调用来执行一些统计信息计算。我必须准确地说我使用的是我配置为使用 MSVC 12.0 编译器的 Qt 5.5 MSVC 2013 套件。

当然,我已经安装了 R 包 Rcpp 和 RInside。

在 Dirk Eddelbuettel 在此主题上的工作之后,我尝试调整其 .pro 文件以使其工作the Qtdensity example,但在编译 .pro 文件时遇到问题。

实际上,这里是编译 .pro 文件产生的不同变量和标志的输出,以及我对这些的每个问题:

项目消息:R_HOME 是 C:\R\R-3.3.1 到目前为止,一切顺利...

项目消息:RLDFLAGS 是 -LC:/R/R-3.3.1/bin/x64 -lR -lm 可以吗?

项目消息:RBLAS 是 -LC:/R/R-3.3.1/bin/x64 -lRblas 可以吗?

项目消息:RLAPACK 是 -LC:/R/R-3.3.1/bin/x64 -lRlapack 可以吗?

项目消息:RCPPINCL 是 -IC:/R/R-3.3.1/library/Rcpp/include 似乎没问题..

项目消息:RCPPLIBS 应该不会是空的,对吧?...

项目消息:RINSIDEINCL 是 -IC:/R/R-3.3.1/library/RInside/include 似乎没问题...

项目消息:RINSIDELIBS 是“C:/R/R-3.3.1/library/RInside/lib/x64/libRInside.a”我应该改用 libRInside.dll 吗?

最后,当我尝试编译 Qtdensity 时,我遇到了以下错误:

C:\R\R-3.3.1\library\RInside\include\RInsideCommon.h:27: erreur : C1083: 无法打开包含文件: 'sys/time.h': 没有这样的文件或目录

当然,我不是高级 C++ 架构师,但如果有人可以帮助我找出应该根据我的系统和环境特性获取 .pro 文件的不同变量的值,那将是很棒的,因为我真的很想利用我在 R 中的学习时间并避免学习 Python -:)

最好的问候。

朱利安

----------编辑------------------------ ----

好的,这里有一些消息:

1) 我在 C:\R\R-3.3.1 目录下安装了 R 3.3.1。 2) 我还尝试创建一个名为 Mingw 32bit R 的新编译工具包,其配置为:

编译器:C:\R\Rtools\mingw_32\bin\g++.exe

调试器:C:\R\Rtools\mingw_32\bin\gdb.exe

Qt 版本:Qt 5.7.0 MingW 32 位。

我想我现在已经正确设置了 .pro 变量:

项目消息:R_HOME 是 C:\R\R-3.3.1

项目消息:RCPPFLAGS 是 -IC:/R/R-3.3.1/include -IC:/R/R-3.3.1/include/x64

项目消息:RLDFLAGS 是 -LC:/R/R-3.3.1/bin/x64 -lR -lm

项目消息:RBLAS 为 -LC:/R/R-3.3.1/bin/x64 -lRblas

项目消息:RLAPACK 是 -LC:/R/R-3.3.1/bin/x64 -lRlapack

项目消息:RCPPINCL 是 -IC:/R/R-3.3.1/library/Rcpp/include

项目消息:RCPPLIBS 是

项目消息:RINSIDEINCL 是 -IC:/R/R-3.3.1/library/RInside/include

项目消息:RINSIDELIBS 是“C:/R/3.3.1/library/RInside/lib/x64/libRInside.a”

....但是在编译时,我收到以下错误...

C:/R/Rtools/mingw_32/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'C:/Program Files/R/R-3.0.3/library/RInside/examples/qt/build-qtdensity-Mingw_32_bit_Rtools-Debug'
g++ -c -pipe -fno-keep-inline-dllexport -IC:/R/R-3.3.1/include -IC:/R/R-3.3.1/include/x64 -IC:/R/R-3.3.1/library/Rcpp/include -IC:/R/R-3.3.1/library/RInside/include -g -std=gnu++11 -frtti -Wall -Wextra -fexceptions -mthreads -DUNICODE -DQT_QML_DEBUG -DQT_SVG_LIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../../qt -I. -IC:/Qt/5.7/mingw53_32/include -IC:/Qt/5.7/mingw53_32/include/QtSvg -IC:/Qt/5.7/mingw53_32/include/QtWidgets -IC:/Qt/5.7/mingw53_32/include/QtGui -IC:/Qt/5.7/mingw53_32/include/QtANGLE -IC:/Qt/5.7/mingw53_32/include/QtCore -Idebug -IC:/Qt/5.7/mingw53_32/mkspecs/win32-g++  -o debug/qtdensity.o ../qtdensity.cpp
In file included from C:/R/Rtools/mingw_32/i686-w64-mingw32/include/combaseapi.h:155:0,
                 from C:/R/Rtools/mingw_32/i686-w64-mingw32/include/objbase.h:14,
                 from C:/R/Rtools/mingw_32/i686-w64-mingw32/include/ole2.h:17,
                 from C:/R/Rtools/mingw_32/i686-w64-mingw32/include/wtypes.h:12,
                 from C:/R/Rtools/mingw_32/i686-w64-mingw32/include/winscard.h:10,
                 from C:/R/Rtools/mingw_32/i686-w64-mingw32/include/windows.h:97,
                 from C:/Qt/5.7/mingw53_32/include/QtCore/qt_windows.h:61,
                 from C:/Qt/5.7/mingw53_32/include/QtGui/qopengl.h:49,
                 from C:/Qt/5.7/mingw53_32/include/QtGui/qopenglcontext.h:60,
                 from C:/Qt/5.7/mingw53_32/include/QtGui/QtGui:32,
                 from ../qtdensity.h:13,
                 from ../qtdensity.cpp:8:
C:/R/Rtools/mingw_32/i686-w64-mingw32/include/objidlbase.h:864:18: error: macro "Realloc" requires 3 arguments, but only 2 given
         SIZE_T cb) = 0;
                  ^
C:/R/Rtools/mingw_32/i686-w64-mingw32/include/objidlbase.h:864:22: error: 'Realloc' declared as a 'virtual' field
         SIZE_T cb) = 0;
                      ^
In file included from C:/R/R-3.3.1/include/R.h:75:0,
                 from C:/R/R-3.3.1/library/Rcpp/include/Rcpp/r/headers.h:52,
                 from C:/R/R-3.3.1/library/Rcpp/include/RcppCommon.h:29,
                 from C:/R/R-3.3.1/library/Rcpp/include/Rcpp.h:27,
                 from C:/R/R-3.3.1/library/RInside/include/RInsideCommon.h:38,
                 from C:/R/R-3.3.1/library/RInside/include/RInside.h:26,
                 from ../qtdensity.h:11,
                 from ../qtdensity.cpp:8:
C:/R/R-3.3.1/include/R_ext/RS.h:71:37: error: expected identifier before '(' token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                     ^
C:/R/R-3.3.1/include/R_ext/RS.h:71:47: error: 'parameter' declared as function returning a function
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                               ^
C:/R/R-3.3.1/include/R_ext/RS.h:71:50: error: expected ')' before ',' token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                                  ^
C:/R/R-3.3.1/include/R_ext/RS.h:71:37: error: expected identifier before '(' token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                     ^
C:/R/R-3.3.1/include/R_ext/RS.h:71:47: error: 'parameter' declared as function returning a function
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                               ^
C:/R/R-3.3.1/include/R_ext/RS.h:71:50: error: expected ')' before ',' token
 #define Free(p)        (R_chk_free( (void *)(p) ), (p) = NULL)
                                                  ^
Makefile.Debug:797: recipe for target 'debug/qtdensity.o' failed

显然,一些包含文件仍然存在问题(是由于 Qt 5.7.0 框架/mingw 编译的库与 RTools 提供的 Mingw 版本之间的差异吗?有什么想法吗?

最好的问候。

朱利安

【问题讨论】:

  • 谢谢你们的 cmets 先生们,我会尝试安装一个 mingw 编译的 Qt 版本并让它全部工作......

标签: c++ r qt


【解决方案1】:

.dll 是在运行时链接的库。链接器需要.a.lib 文件。

RCPPLIBS 在 Rcpp (>= 0.11.0) 时为空,可以省略。

您面临的错误是因为显然 Rinside 不适合使用 Visual C++ 编译。 sys/time.h 不是 MSVC 提供的。

您正在尝试使用用 gcc(很可能是 mingw)编译的 Rinside 版本。这不起作用,因为您不能混合使用不同编译器编译的 C++ 库。一切都必须使用相同的编译器进行编译。由于使用 MSVC 编译 R 需要修补 很多 代码,因此您必须切换到 mingw 并使用使用相同 mingw 版本编译的 Qt,或者使用用于 Rinside 的 mingw 重新编译 Qt。 p>

【讨论】:

  • R 根本无法在 MSCV 下构建。因此没有 Rcpp。因此没有 RInside。看到我的回答比你早几秒钟。
  • @DirkEddelbuettel 除非我弄错了,R 本身只公开一个 C 接口,并且在 Windows 上,C ABI 在各种编译器之间互操作,甚至是非 C,所以你绝对可以在 MSVC 下编译 Rcpp它可以消耗在mingw下编译的R dll。似乎 R 的某些标题可能需要一两次调整。
【解决方案2】:

您错过了Rcpp FAQ vignette 的问题 1.3 和特定的 2.9。

请允许我在这里再重复一遍 2.9(从源头看,pdf 更漂亮,并且为这里的降价做了手工改编):

我可以在 Visual Studio 中使用Rcpp 吗?

没有机会。

那不是因为我们是吝啬鬼,而是因为R 和 Visual Studio 根本无法相处。正如Rcpp 是关于 使用C++ 接口扩展R,我们受 可用的工具链。而R 根本无法编译 与 Visual Studio。如果您仍然不满意,请向其供应商投诉。

但不要害怕:您可以使用 Qt 在 Windows 上构建并拥有 RInside。但是你必须一直使用MinGW。早在我需要从源代码构建 Qt 来实现这一点的时候,这些天我相信你会得到一个合适的预构建库。不过,如果您遇到问题,请从源代码构建它以在整个项目中拥有相同的工具链。这对于 C++ 至关重要。

【讨论】:

    猜你喜欢
    • 2012-08-30
    • 1970-01-01
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    • 2018-11-03
    相关资源
    最近更新 更多