How to use OpenBlas Lapacke together with Rcpp











up vote
2
down vote

favorite












I have some running c++ code using the Lapacke version that comes with OpenBlas. I would like to include this code into an R package and transfer data between that function and R using the Rcpp package. But somehow the two seem not to like each other. As soon as I have #include <lapacke.h> and #include <Rcpp.h> in one source file it isn't compiling anymore. Both separately work fine. There is a whole bunch off error messages which as far as I can tell say that Rcpp is broken (e.g /home/Alex/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/traits/traits.h:32:15: error: expected ‘)’ before ‘__extension__’).



I have no idea why this happens. Is there a way to use both at same time?
Or should I do something completely different?



Here is a minimal example that gives me the error:





  1. I created a package using



    Rcpp::Rcpp.package.skeleton("LT", example_code = FALSE)



  2. I added a .cpp file to /src containing



    #include <lapacke.h>
    #include <Rcpp.h>

    int test_LAPACK(){
    return(1);
    }



  3. I added a Makvars file to /src containing



    PKG_CXXFLAGS = -I/opt/OpenBLAS/include
    PKG_LIBS = -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran
    CXX_STD = CXX11



  4. Compile and install



    Rcpp::compileAttributes("LT")
    devtools::install("LT")











share|improve this question




















  • 1




    @DirkEddelbuettel At least for my simple example changing the order of the includes seem to work. Thanks for this tip.
    – Alex
    Nov 10 at 17:01










  • That is very often the case. Large projects tend to define things, other projects may get "hit" by that. Experience teaches you to put certain things first or last. Worst case you have conflicting needs...
    – Dirk Eddelbuettel
    Nov 10 at 17:08












  • But yes, added that comment as an edit to the answer--the key really is the link order here.
    – Dirk Eddelbuettel
    Nov 10 at 17:34















up vote
2
down vote

favorite












I have some running c++ code using the Lapacke version that comes with OpenBlas. I would like to include this code into an R package and transfer data between that function and R using the Rcpp package. But somehow the two seem not to like each other. As soon as I have #include <lapacke.h> and #include <Rcpp.h> in one source file it isn't compiling anymore. Both separately work fine. There is a whole bunch off error messages which as far as I can tell say that Rcpp is broken (e.g /home/Alex/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/traits/traits.h:32:15: error: expected ‘)’ before ‘__extension__’).



I have no idea why this happens. Is there a way to use both at same time?
Or should I do something completely different?



Here is a minimal example that gives me the error:





  1. I created a package using



    Rcpp::Rcpp.package.skeleton("LT", example_code = FALSE)



  2. I added a .cpp file to /src containing



    #include <lapacke.h>
    #include <Rcpp.h>

    int test_LAPACK(){
    return(1);
    }



  3. I added a Makvars file to /src containing



    PKG_CXXFLAGS = -I/opt/OpenBLAS/include
    PKG_LIBS = -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran
    CXX_STD = CXX11



  4. Compile and install



    Rcpp::compileAttributes("LT")
    devtools::install("LT")











share|improve this question




















  • 1




    @DirkEddelbuettel At least for my simple example changing the order of the includes seem to work. Thanks for this tip.
    – Alex
    Nov 10 at 17:01










  • That is very often the case. Large projects tend to define things, other projects may get "hit" by that. Experience teaches you to put certain things first or last. Worst case you have conflicting needs...
    – Dirk Eddelbuettel
    Nov 10 at 17:08












  • But yes, added that comment as an edit to the answer--the key really is the link order here.
    – Dirk Eddelbuettel
    Nov 10 at 17:34













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have some running c++ code using the Lapacke version that comes with OpenBlas. I would like to include this code into an R package and transfer data between that function and R using the Rcpp package. But somehow the two seem not to like each other. As soon as I have #include <lapacke.h> and #include <Rcpp.h> in one source file it isn't compiling anymore. Both separately work fine. There is a whole bunch off error messages which as far as I can tell say that Rcpp is broken (e.g /home/Alex/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/traits/traits.h:32:15: error: expected ‘)’ before ‘__extension__’).



I have no idea why this happens. Is there a way to use both at same time?
Or should I do something completely different?



Here is a minimal example that gives me the error:





  1. I created a package using



    Rcpp::Rcpp.package.skeleton("LT", example_code = FALSE)



  2. I added a .cpp file to /src containing



    #include <lapacke.h>
    #include <Rcpp.h>

    int test_LAPACK(){
    return(1);
    }



  3. I added a Makvars file to /src containing



    PKG_CXXFLAGS = -I/opt/OpenBLAS/include
    PKG_LIBS = -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran
    CXX_STD = CXX11



  4. Compile and install



    Rcpp::compileAttributes("LT")
    devtools::install("LT")











share|improve this question















I have some running c++ code using the Lapacke version that comes with OpenBlas. I would like to include this code into an R package and transfer data between that function and R using the Rcpp package. But somehow the two seem not to like each other. As soon as I have #include <lapacke.h> and #include <Rcpp.h> in one source file it isn't compiling anymore. Both separately work fine. There is a whole bunch off error messages which as far as I can tell say that Rcpp is broken (e.g /home/Alex/R/x86_64-pc-linux-gnu-library/3.4/Rcpp/include/Rcpp/traits/traits.h:32:15: error: expected ‘)’ before ‘__extension__’).



I have no idea why this happens. Is there a way to use both at same time?
Or should I do something completely different?



Here is a minimal example that gives me the error:





  1. I created a package using



    Rcpp::Rcpp.package.skeleton("LT", example_code = FALSE)



  2. I added a .cpp file to /src containing



    #include <lapacke.h>
    #include <Rcpp.h>

    int test_LAPACK(){
    return(1);
    }



  3. I added a Makvars file to /src containing



    PKG_CXXFLAGS = -I/opt/OpenBLAS/include
    PKG_LIBS = -L/opt/OpenBLAS/lib -lopenblas -lpthread -lgfortran
    CXX_STD = CXX11



  4. Compile and install



    Rcpp::compileAttributes("LT")
    devtools::install("LT")








c++ r rcpp r-package lapacke






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 16:49

























asked Nov 10 at 16:42









Alex

3,21521530




3,21521530








  • 1




    @DirkEddelbuettel At least for my simple example changing the order of the includes seem to work. Thanks for this tip.
    – Alex
    Nov 10 at 17:01










  • That is very often the case. Large projects tend to define things, other projects may get "hit" by that. Experience teaches you to put certain things first or last. Worst case you have conflicting needs...
    – Dirk Eddelbuettel
    Nov 10 at 17:08












  • But yes, added that comment as an edit to the answer--the key really is the link order here.
    – Dirk Eddelbuettel
    Nov 10 at 17:34














  • 1




    @DirkEddelbuettel At least for my simple example changing the order of the includes seem to work. Thanks for this tip.
    – Alex
    Nov 10 at 17:01










  • That is very often the case. Large projects tend to define things, other projects may get "hit" by that. Experience teaches you to put certain things first or last. Worst case you have conflicting needs...
    – Dirk Eddelbuettel
    Nov 10 at 17:08












  • But yes, added that comment as an edit to the answer--the key really is the link order here.
    – Dirk Eddelbuettel
    Nov 10 at 17:34








1




1




@DirkEddelbuettel At least for my simple example changing the order of the includes seem to work. Thanks for this tip.
– Alex
Nov 10 at 17:01




@DirkEddelbuettel At least for my simple example changing the order of the includes seem to work. Thanks for this tip.
– Alex
Nov 10 at 17:01












That is very often the case. Large projects tend to define things, other projects may get "hit" by that. Experience teaches you to put certain things first or last. Worst case you have conflicting needs...
– Dirk Eddelbuettel
Nov 10 at 17:08






That is very often the case. Large projects tend to define things, other projects may get "hit" by that. Experience teaches you to put certain things first or last. Worst case you have conflicting needs...
– Dirk Eddelbuettel
Nov 10 at 17:08














But yes, added that comment as an edit to the answer--the key really is the link order here.
– Dirk Eddelbuettel
Nov 10 at 17:34




But yes, added that comment as an edit to the answer--the key really is the link order here.
– Dirk Eddelbuettel
Nov 10 at 17:34












1 Answer
1






active

oldest

votes

















up vote
4
down vote



accepted










It actually works on my system following a standard sudo apt install liblapacke-dev provided I also change the include order.



Witness:



Source



rob:/tmp/lapacke/LT$ cat src/lt.cpp 
#include <Rcpp.h>
#include <lapacke.h>

int test_LAPACK(){
return(1);
}
rob:/tmp/lapacke/LT$ ls src/ ## no Makevars needed
lt.cpp
rob:/tmp/lapacke/LT$


Build



rob:/tmp/lapacke/LT$ build.r 
* checking for file ‘./DESCRIPTION’ ... OK
* preparing ‘LT’:
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
* saving partial Rd database
* cleaning src
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
Removed empty directory ‘LT/R’
* building ‘LT_1.0.tar.gz’

rob:/tmp/lapacke/LT$


Install



rob:/tmp/lapacke/LT$ install.r LT_1.0.tar.gz 
* installing *source* package ‘LT’ ...
** libs
ccache g++ -I"/usr/share/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -march=native -c lt.cpp -o lt.o
ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LT.so lt.o -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/LT/libs
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (LT)
rob:/tmp/lapacke/LT$


Run



(After I added a line // [[Rcpp::export]], ran compileAtttributes() and rebuilt and installed.)



rob:/tmp/lapacke/LT$ r -lLT -p -e'test_LAPACK()'
[1] 1
rob:/tmp/lapacke/LT$


Summary



Check your compiler. There is no fundamental reason this should not work, and it works here (Ubuntu 18.04).






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241120%2fhow-to-use-openblas-lapacke-together-with-rcpp%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote



    accepted










    It actually works on my system following a standard sudo apt install liblapacke-dev provided I also change the include order.



    Witness:



    Source



    rob:/tmp/lapacke/LT$ cat src/lt.cpp 
    #include <Rcpp.h>
    #include <lapacke.h>

    int test_LAPACK(){
    return(1);
    }
    rob:/tmp/lapacke/LT$ ls src/ ## no Makevars needed
    lt.cpp
    rob:/tmp/lapacke/LT$


    Build



    rob:/tmp/lapacke/LT$ build.r 
    * checking for file ‘./DESCRIPTION’ ... OK
    * preparing ‘LT’:
    * checking DESCRIPTION meta-information ... OK
    * cleaning src
    * installing the package to process help pages
    * saving partial Rd database
    * cleaning src
    * checking for LF line-endings in source and make files and shell scripts
    * checking for empty or unneeded directories
    Removed empty directory ‘LT/R’
    * building ‘LT_1.0.tar.gz’

    rob:/tmp/lapacke/LT$


    Install



    rob:/tmp/lapacke/LT$ install.r LT_1.0.tar.gz 
    * installing *source* package ‘LT’ ...
    ** libs
    ccache g++ -I"/usr/share/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -march=native -c lt.cpp -o lt.o
    ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LT.so lt.o -L/usr/lib/R/lib -lR
    installing to /usr/local/lib/R/site-library/LT/libs
    ** help
    *** installing help indices
    ** building package indices
    ** testing if installed package can be loaded
    * DONE (LT)
    rob:/tmp/lapacke/LT$


    Run



    (After I added a line // [[Rcpp::export]], ran compileAtttributes() and rebuilt and installed.)



    rob:/tmp/lapacke/LT$ r -lLT -p -e'test_LAPACK()'
    [1] 1
    rob:/tmp/lapacke/LT$


    Summary



    Check your compiler. There is no fundamental reason this should not work, and it works here (Ubuntu 18.04).






    share|improve this answer



























      up vote
      4
      down vote



      accepted










      It actually works on my system following a standard sudo apt install liblapacke-dev provided I also change the include order.



      Witness:



      Source



      rob:/tmp/lapacke/LT$ cat src/lt.cpp 
      #include <Rcpp.h>
      #include <lapacke.h>

      int test_LAPACK(){
      return(1);
      }
      rob:/tmp/lapacke/LT$ ls src/ ## no Makevars needed
      lt.cpp
      rob:/tmp/lapacke/LT$


      Build



      rob:/tmp/lapacke/LT$ build.r 
      * checking for file ‘./DESCRIPTION’ ... OK
      * preparing ‘LT’:
      * checking DESCRIPTION meta-information ... OK
      * cleaning src
      * installing the package to process help pages
      * saving partial Rd database
      * cleaning src
      * checking for LF line-endings in source and make files and shell scripts
      * checking for empty or unneeded directories
      Removed empty directory ‘LT/R’
      * building ‘LT_1.0.tar.gz’

      rob:/tmp/lapacke/LT$


      Install



      rob:/tmp/lapacke/LT$ install.r LT_1.0.tar.gz 
      * installing *source* package ‘LT’ ...
      ** libs
      ccache g++ -I"/usr/share/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -march=native -c lt.cpp -o lt.o
      ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LT.so lt.o -L/usr/lib/R/lib -lR
      installing to /usr/local/lib/R/site-library/LT/libs
      ** help
      *** installing help indices
      ** building package indices
      ** testing if installed package can be loaded
      * DONE (LT)
      rob:/tmp/lapacke/LT$


      Run



      (After I added a line // [[Rcpp::export]], ran compileAtttributes() and rebuilt and installed.)



      rob:/tmp/lapacke/LT$ r -lLT -p -e'test_LAPACK()'
      [1] 1
      rob:/tmp/lapacke/LT$


      Summary



      Check your compiler. There is no fundamental reason this should not work, and it works here (Ubuntu 18.04).






      share|improve this answer

























        up vote
        4
        down vote



        accepted







        up vote
        4
        down vote



        accepted






        It actually works on my system following a standard sudo apt install liblapacke-dev provided I also change the include order.



        Witness:



        Source



        rob:/tmp/lapacke/LT$ cat src/lt.cpp 
        #include <Rcpp.h>
        #include <lapacke.h>

        int test_LAPACK(){
        return(1);
        }
        rob:/tmp/lapacke/LT$ ls src/ ## no Makevars needed
        lt.cpp
        rob:/tmp/lapacke/LT$


        Build



        rob:/tmp/lapacke/LT$ build.r 
        * checking for file ‘./DESCRIPTION’ ... OK
        * preparing ‘LT’:
        * checking DESCRIPTION meta-information ... OK
        * cleaning src
        * installing the package to process help pages
        * saving partial Rd database
        * cleaning src
        * checking for LF line-endings in source and make files and shell scripts
        * checking for empty or unneeded directories
        Removed empty directory ‘LT/R’
        * building ‘LT_1.0.tar.gz’

        rob:/tmp/lapacke/LT$


        Install



        rob:/tmp/lapacke/LT$ install.r LT_1.0.tar.gz 
        * installing *source* package ‘LT’ ...
        ** libs
        ccache g++ -I"/usr/share/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -march=native -c lt.cpp -o lt.o
        ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LT.so lt.o -L/usr/lib/R/lib -lR
        installing to /usr/local/lib/R/site-library/LT/libs
        ** help
        *** installing help indices
        ** building package indices
        ** testing if installed package can be loaded
        * DONE (LT)
        rob:/tmp/lapacke/LT$


        Run



        (After I added a line // [[Rcpp::export]], ran compileAtttributes() and rebuilt and installed.)



        rob:/tmp/lapacke/LT$ r -lLT -p -e'test_LAPACK()'
        [1] 1
        rob:/tmp/lapacke/LT$


        Summary



        Check your compiler. There is no fundamental reason this should not work, and it works here (Ubuntu 18.04).






        share|improve this answer














        It actually works on my system following a standard sudo apt install liblapacke-dev provided I also change the include order.



        Witness:



        Source



        rob:/tmp/lapacke/LT$ cat src/lt.cpp 
        #include <Rcpp.h>
        #include <lapacke.h>

        int test_LAPACK(){
        return(1);
        }
        rob:/tmp/lapacke/LT$ ls src/ ## no Makevars needed
        lt.cpp
        rob:/tmp/lapacke/LT$


        Build



        rob:/tmp/lapacke/LT$ build.r 
        * checking for file ‘./DESCRIPTION’ ... OK
        * preparing ‘LT’:
        * checking DESCRIPTION meta-information ... OK
        * cleaning src
        * installing the package to process help pages
        * saving partial Rd database
        * cleaning src
        * checking for LF line-endings in source and make files and shell scripts
        * checking for empty or unneeded directories
        Removed empty directory ‘LT/R’
        * building ‘LT_1.0.tar.gz’

        rob:/tmp/lapacke/LT$


        Install



        rob:/tmp/lapacke/LT$ install.r LT_1.0.tar.gz 
        * installing *source* package ‘LT’ ...
        ** libs
        ccache g++ -I"/usr/share/R/include" -DNDEBUG -I"/usr/local/lib/R/site-library/Rcpp/include" -fpic -g -O3 -Wall -pipe -march=native -c lt.cpp -o lt.o
        ccache g++ -Wl,-S -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o LT.so lt.o -L/usr/lib/R/lib -lR
        installing to /usr/local/lib/R/site-library/LT/libs
        ** help
        *** installing help indices
        ** building package indices
        ** testing if installed package can be loaded
        * DONE (LT)
        rob:/tmp/lapacke/LT$


        Run



        (After I added a line // [[Rcpp::export]], ran compileAtttributes() and rebuilt and installed.)



        rob:/tmp/lapacke/LT$ r -lLT -p -e'test_LAPACK()'
        [1] 1
        rob:/tmp/lapacke/LT$


        Summary



        Check your compiler. There is no fundamental reason this should not work, and it works here (Ubuntu 18.04).







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 10 at 17:34

























        answered Nov 10 at 17:01









        Dirk Eddelbuettel

        273k37504596




        273k37504596






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241120%2fhow-to-use-openblas-lapacke-together-with-rcpp%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Error while running script in elastic search , gateway timeout

            Adding quotations to stringified JSON object values