-2

The software I am talking of contains 5 files and compiles "perfectly fine" on openSUSE 11.3 with gcc-4.5.1:

The same software shows the following error on Windows XP with Mingw (gcc-4.6.3).

UPDATE

The problem is discovered.

The problem is w.r.t the R's function parseEval. There are two similar functions: parseEval and parseEvalQ. The former returns a value, and the other returns void.

I have used parseEval in a C++ plus Qt project, and it works very fine on Linux, and throws the above shown error on Windows.

Here is the reproducible example:

demo.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";
}

Corresponding .pro file:

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

enter image description here

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
  • Can you give us a bit more information? File structure, if you've tried anything to troubleshoot etc? – Fabian Tamp Nov 07 '12 at 08:51
  • I can provide the .pro file, if that's what you want? What else info did you mean? @Fabian – Aquarius_Girl Nov 07 '12 at 08:54
  • 1
    You are using different versions of GCC under different platforms with different builds of Qt. Of course this _may_ happen. It's hard to say without further information (i.e. code), though. – SingerOfTheFall Nov 07 '12 at 08:58
  • @SingerOfTheFall I do understand that, but the code is in 5 files interdependent on each other. Not sure how should I produce the code here. :( – Aquarius_Girl Nov 07 '12 at 09:00
  • @SingerOfTheFall See the pro file please. – Aquarius_Girl Nov 07 '12 at 09:02
  • Show also the relevant C++ code – Basile Starynkevitch Nov 07 '12 at 10:20
  • @BasileStarynkevitch Alright, I'll post two .cpp and .h files, out of the five which I think are relevant.. – Aquarius_Girl Nov 07 '12 at 10:22
  • ***I have already mailed this to `rcpp-devel`.*** My mail is awaiting moderation there. – Aquarius_Girl Nov 08 '12 at 07:04
  • Previously I didn't know that was related to R hence didn't tag it as R. – Aquarius_Girl Nov 08 '12 at 07:07
  • Briefly: a) rcpp-devel is a subscriber-only list, and I will not manually moderate you or anybody else. Subscribe, or be ignored. b) This is obviously a linker issue with a problem you have in your toolchain. See all the previous answers to all your previous (near identical) questions. I recommend the .pro file I post, and make sure you *use the same gcc version for Qt and R*. c) I just deleted your post as it had a >200kb attachment. What on Earth were you thinking? There is a default 40kb limit. – Dirk Eddelbuettel Nov 08 '12 at 12:55
  • @DirkEddelbuettel I "did" subscribe to that list, that's why I could send the mail. The reason of the attachment is that the text on windows terminal cannot be selected by mouse. Therefore I had no choice other than posting the png to show the full compilation message. You said: *" I recommend the .pro file I post,"* If you mean the QtDensity pro file for Windows, then I have tried it many times, it does not work directly on Windows. And yes, gcc version for Qt and R "are" same in my case. I have manually installed the required mingw version for Qt. – Aquarius_Girl Nov 08 '12 at 14:05
  • I am not going to explain to you how to use a Windows computer but try right-clicking the title bar and follow edit. As for your issues, I suspect they are home grown as I and other had luck building Qt and R apps the way it is recommended and documented in the respective Qt and R documentation. You are free to continue to do things your way, but it may also continue to not work that way. And as I must have said a dozen times now: _post on the list_ where you find other R + Qt + RInside users which you _do not find here_. – Dirk Eddelbuettel Nov 08 '12 at 14:35
  • @DirkEddelbuettel You said: **"As for your issues, I suspect they are home grown "**. I agree. Today I again compiled the above reproducible program with the standard "makefile" of R for windows. It "did" compile properly. So, this proves that the fault is with my .pro file, again. This time I couldn't doubt my pro file because the problem occurs ONLY with the function `parseEval`. Once I comment out that particular function, whole project (including many other functions of R) compiles fine. Again, please pardon my ignorance. – Aquarius_Girl Nov 09 '12 at 08:40

2 Answers2

1

Linking semantics is different in Linux and in Windows, notably for dynamic libraries.

I suggest to read Levine's linkers and loaders book.

See also this question, and look for Gcc function attributes, dllexport and dllimport.

With Qt, you may need to use Q_DECL_EXPORT etc.... (This Qt macro will work both on Linux and on Windows).

Community
  • 1
  • 1
Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
0

I said:

This is solved. The problem was NOT related to the .pro file, it was related to the syntax of parseEval function. The RInside I have on Linux is older than RInside I have on Windows. The versions of Rcpp installed are also different on my Linux system and Windows system.

This syntax of parseEval - int returnValue = R.parseEval ("sum"); works fine on Linux with older RInside but fails on Windows with newer RInside.

So, I modified the above code as follows and it compiled successfully with the above .pro file.

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

This did compile successfully, but to my horror this joy was just the calmness before the storm!
The same error had now shifted to the run time!

So, the permanent solution to this error is editing the .pro file and linking Rcpp AFTER RInside:

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

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411