Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use Rcpp in Qt (with Mac) [Almost Solved]?
Forum Updated to NodeBB v4.3 + New Features

How to use Rcpp in Qt (with Mac) [Almost Solved]?

Scheduled Pinned Locked Moved General and Desktop
rcpp qt mac
25 Posts 3 Posters 8.4k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #2

    Hi!
    Do you already know GSL? http://www.gnu.org/software/gsl/

    1 Reply Last reply
    0
    • N Offline
      N Offline
      newe12
      wrote on last edited by newe12
      #3

      Thanks so far!

      Well I found an approximation function for the cdf of standard normal distribution and http://dirk.eddelbuettel.com/code/rcpp/html/Rmath_8h.html

      Rcpp covers a lot of statistics functionality!

      What would be the easiest way to use Rcpp or Rmath.h in Qt creator (if I do not need the whole functionality of Rcpp, but just some of Rmath.h)?

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by A Former User
        #4

        Hi,

        that's easy. Rcpp is in the Debian and Ubuntu repositories. So the first step is to install it:
        sudo apt-get install r-cran-rcpp

        Next step is to create a new project or open an existing one in QtCreator. In your *.pro file add the include paths for R and Rcpp and tell the linker about the R library:

        INCLUDEPATH += /usr/share/R/include
        INCLUDEPATH += /usr/lib/R/site-library/Rcpp/include
        LIBS += -L/usr/lib -lR
        

        Now you're up and running. Following the example from the Rcpp introduction (http://dirk.eddelbuettel.com/code/rcpp/Rcpp-introduction.pdf, page 3):

        // ...
        #include <Rcpp.h>
        
        RcppExport SEXP convolve3cpp(SEXP a, SEXP b) {
            Rcpp::NumericVector xa(a);
            Rcpp::NumericVector xb(b);
            int n_xa = xa.size(), n_xb = xb.size();
            int nab = n_xa + n_xb - 1;
            Rcpp::NumericVector xab(nab);
            for (int i = 0; i < n_xa; i++)
            for (int j = 0; j < n_xb; j++)
            xab[i + j] += xa[i] * xb[j];
            return xab;
        }
        
        int main(int argc, char *argv[])
        {
            QApplication app(argc, argv);
        
            // your code 
        
            return app.exec();
        }
        

        Cheers!

        1 Reply Last reply
        1
        • N Offline
          N Offline
          newe12
          wrote on last edited by newe12
          #5

          Thanks for your helpful reply!

          Well, I have got a problem with the initial task: "sudo: apt-get: command not found" - in the Terminal.
          I am using a Mac OS X Yosemite.

          So I have been only able to install it in R Studio... (where it runs nicely!)

          But, I would like to use Rcpp in Qt creator!

          Any suggestions to install and run it as it should work?

          Or is there an easier way of installing it directly via Qt?

          Please let me know!

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #6

            There is nothing as "installing it via Qt". If you have installed it in R Studio then you just need to locate the R library and the header files I mentioned above. Then adjust the paths in your *.pro file.

            1 Reply Last reply
            1
            • N Offline
              N Offline
              newe12
              wrote on last edited by
              #7

              Thanks! I understand.

              Well in R Studio I identified the R library with ".Library"and I got:

              .Library
              [1] "/Library/Frameworks/R.framework/Resources/library"

              In combination with your suggestion I tried this:
              INCLUDEPATH += /Users/xy/share/R/include
              INCLUDEPATH += /Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/include
              LIBS += -L/Users/xy/lib -lR
              but it was not working...

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #8

                Sorry, but I can't help you with Mac OS. :-(

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  newe12
                  wrote on last edited by
                  #9

                  Okay! Thank you very much for your help!

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #10

                    You're welcome!

                    1 Reply Last reply
                    1
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Hi and welcome to devnet,

                      Try with -framework R in place of -lR

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      1
                      • N Offline
                        N Offline
                        newe12
                        wrote on last edited by newe12
                        #12

                        Thanks!

                        Well, now I have got:
                        INCLUDEPATH += /Users/xy/share/R/include
                        INCLUDEPATH += /Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/include
                        LIBS += -L/Users/xy/Library -framework R

                        but I still get:
                        'Rcpp.h' file not found

                        also if change to:
                        LIBS += -L/Users/xy/Library/Frameworks/R.framework/

                        and when I typed in R Studio:
                        getw()

                        I got:
                        /Users/xy

                        Sorry, but I do not find the mistake. Any idea?

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by SGaist
                          #13

                          It depends on how you wrote your includes

                          What mistake are you thinking about ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • N Offline
                            N Offline
                            newe12
                            wrote on last edited by newe12
                            #14

                            I wrote my include: #include "Rcpp.h" in mainwindow.cpp.
                            It is not conflicting with: #include "math.h", or?

                            And it displays: directory not found for: LIBS += -L/Users/xy/Library/Frameworks/R.framework/ and also for: LIBS += -L/Users/xy/Library -framework R

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              To add a path for frameworks you should user -F /Users/xy/Library/Frameworks/
                              The includes are generally in fwname.framework/Headers

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              1
                              • N Offline
                                N Offline
                                newe12
                                wrote on last edited by newe12
                                #16

                                Hi!

                                Sorry, but Qt still does not find the "Rccp.h" file. I tried to include #include "Rcpp.h" in mainwindow.cpp or in mainwindow.h. Or should I include it in main.cpp?

                                and additionally I wrote in the .pro-file:
                                HEADERS += mainwindow.h

                                FORMS += mainwindow.ui

                                INCLUDEPATH += /Users/xy/share/R/include
                                INCLUDEPATH += /Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/include
                                LIBS += -L/Users/xy/Library/Frameworks/R.framework/
                                INCLUDEPATH += -F/Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/include

                                and I tried: INCLUDEPATH += "/Users/.../include" using: "..." but same result.

                                In RStudio it gives me:

                                .Library
                                [1] "/Library/Frameworks/R.framework/Resources/library"
                                getwd()
                                [1] "/Users/xy"

                                So I combined: "/Users/xy/Library/Frameworks/R.framework/Resources/library"

                                Unfortunately, always the same result 'Rcpp.h' not found.

                                Even they: https://stat.ethz.ch/pipermail/r-sig-mac/2011-May/008270.html found
                                "/Library/Frameworks/R.framework/Resources/library" should be alright!

                                Has got anyone an idea?

                                I just want to use 'Rcpp.h' (which I already installed via RStudio, where it loads and runs without any problems) in Qt with a Mac. :-)

                                1 Reply Last reply
                                0
                                • N Offline
                                  N Offline
                                  newe12
                                  wrote on last edited by
                                  #17

                                  Has anyone an idea to get Rcpp.h http://dirk.eddelbuettel.com/code/rcpp/html/Rmath_8h.html
                                  running in Qt with a Mac?

                                  1 Reply Last reply
                                  0
                                  • ? Offline
                                    ? Offline
                                    A Former User
                                    wrote on last edited by
                                    #18

                                    Hi again!
                                    Can you open the directory "/Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/include" with a file manager? Does it contain the file "Rcpp.h" ?

                                    1 Reply Last reply
                                    0
                                    • N Offline
                                      N Offline
                                      newe12
                                      wrote on last edited by
                                      #19

                                      Hi,
                                      I tried to re-install Rcpp.h:

                                      • installing source package ‘Rcpp’ ...
                                        ** Paket ‘Rcpp’ erfolgreich entpackt und MD5 Summen überprüft
                                        ** libs
                                        clang++ -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I../inst/include/ -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include
                                        ...
                                        ...
                                        clang++ -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/Library/Frameworks/R.framework/Resources/lib -L/usr/local/lib -o Rcpp.so Date.o Module.o Rcpp_init.o api.o attributes.o barrier.o -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation
                                        installing to /Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/libs
                                        ** R
                                        ** inst
                                        ** preparing package for lazy loading
                                        ** help
                                        *** installing help indices
                                        ** building package indices
                                        ** installing vignettes
                                        ** testing if installed package can be loaded
                                      • DONE (Rcpp)

                                      then I used:
                                      INCLUDEPATH += /Users/xy/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include
                                      LIBS += -I/Library/Frameworks/R.framework/Resources/include
                                      or
                                      LIBS += -F/Library/Frameworks/R.framework/Resources/include

                                      It still does not run!

                                      1 Reply Last reply
                                      0
                                      • ? Offline
                                        ? Offline
                                        A Former User
                                        wrote on last edited by
                                        #20

                                        Hallo :-)

                                        -o Rcpp.so Date.o Module.o Rcpp_init.o api.o attributes.o

                                        I see that some object code files have been installed. But are you really sure that the file "Rcpp.h" exists in "/Users/xy/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" ? Maybe the Rcpp project has been split in two separate packages: One package only for software that uses Rcpp binaries and a second package for developers that includes all the header files (so called "-dev" package)?

                                        N 1 Reply Last reply
                                        1
                                        • ? A Former User

                                          Hallo :-)

                                          -o Rcpp.so Date.o Module.o Rcpp_init.o api.o attributes.o

                                          I see that some object code files have been installed. But are you really sure that the file "Rcpp.h" exists in "/Users/xy/Library/Frameworks/R.framework/Versions/3.1/Resources/library/Rcpp/include" ? Maybe the Rcpp project has been split in two separate packages: One package only for software that uses Rcpp binaries and a second package for developers that includes all the header files (so called "-dev" package)?

                                          N Offline
                                          N Offline
                                          newe12
                                          wrote on last edited by newe12
                                          #21

                                          Hi Wieland!

                                          Thanks! Yes it exists!

                                          I checked (in the Terminal): cd /Library/Frameworks/R.framework/Resources/library
                                          and then "ls"

                                          And it is there: Rcpp

                                          Then i changed to: cd Rcpp and "ls" gave me:
                                          CITATION NAMESPACE THANKS examples libs
                                          DESCRIPTION NEWS.Rd announce help prompt
                                          INDEX R discovery html skeleton
                                          Meta README doc

                                          This was initially downloaded from: http://cran.r-project.org/web/packages/Rcpp/index.html

                                          And I changed:
                                          INCLUDEPATH += /Users/xy/Library/Frameworks/R.framework/Resources/library/Rcpp/include
                                          LIBS += -I/Users/xy/Library/ -framework R
                                          in the .Pro-file.

                                          Any ideas?

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved