-2

我正在谈论的软件包含 5 个文件,并在以下位置编译“非常好openSUSE 11.3gcc-4.5.1

相同的软件显示以下错误Windows XPMingw (gcc-4.6.3)

更新

问题被发现了。

问题出在R的功能上parseEval。有两个类似的功能:parseEvalparseEvalQ。前者返回一个值,而另一个返回 void。

parseEval在 C++ 和 Qt 项目中使用过,它在 Linux 上运行良好,并在 Windows 上抛出上述错误。

这是可重现的示例:

演示.cpp

#include <iostream>
#include <RInside.h>
#include <Rcpp.h>

RInside R (0, NULL);
RInside & qtToR (R);

int main ()
{
    int numberOne = 1;
    int numberTwo = 2;

    qtToR ["numberOne"] = numberOne;
    qtToR ["numberTwo"] = numberTwo;

    R.parseEvalQ ("sum = numberOne + numberTwo;");

    int returnValue = R.parseEval ("sum");
    std :: cout << "\n" << returnValue << "\n";
}

对应的.pro文件:

TEMPLATE    = app
TARGET      =
DEPENDPATH  += .

SOURCES     += demo.cpp

INCLUDEPATH += .
INCLUDEPATH += c:/R-2.15.1/include
INCLUDEPATH += c:/R-2.15.1/library/Rcpp/include
INCLUDEPATH += c:/R-2.15.1/library/RInside/include

LIBS        += -Lc:/R-2.15.1/bin/i386 -lR
LIBS        += -Lc:/R-2.15.1/library/Rcpp/libs/i386 -lRcpp
LIBS        += -Lc:/R-2.15.1/library/RInside/libs/i386 -lRInside

# You'll keep pulling your hair if you miss this statement when you are on windows.
CONFIG      += console

在此处输入图像描述

4

2 回答 2

1

Linux 和 Windows 中的链接语义不同,特别是对于动态库。

我建议阅读Levine 的链接器和加载器书。

另请参阅此问题,并查找Gcc 函数属性和.dllexportdllimport

使用 Qt,您可能需要使用Q_DECL_EXPORT等....(此 Qt 宏在 Linux 和 Windows 上都可以使用)。

于 2012-11-07T08:59:29.283 回答
0

我说:

这解决了。该问题与 .pro 文件无关,与parseEval函数的语法有关。我在 Linux 上的 RInside 比我在 Windows 上的 RInside 更老。我的Linux系统和Windows系统上安装的Rcpp版本也不同。

这种语法parseEval- int returnValue = R.parseEval ("sum"); 在具有较旧 RInside 的 Linux 上运行良好,但在具有较新 RInside 的 Windows 上失败。

因此,我将上面的代码修改如下,并使用上面的 .pro 文件成功编译。

SEXP ans; int returnValue = R.parseEval ("sum", ans);

这确实编译成功,但令我恐惧的是,这种喜悦只是暴风雨前的平静!
同样的错误现在转移到了运行时!

因此,此错误的永久解决方案是编辑 .pro 文件并在RInside之后链接Rcpp

LIBS += -Lc:/R-2.15.1/library/RInside/libs/i386 -lRInside
LIBS += -Lc:/R-2.15.1/library/Rcpp/libs/i386 -lRcpp

于 2012-12-13T09:09:51.970 回答