Error in linking gfortran to LAPACK and BLAS











up vote
0
down vote

favorite
1












I have installed LAPACK and BLAS from Synaptic package manager in Ubuntu.



whereis libblas
libblas: /usr/lib/libblas.so /usr/lib/libblas.a /usr/lib/libblas

whereis liblapack
liblapack: /usr/lib/liblapack.a /usr/lib/liblapack.so


When I try to compile the randomsys1 example with gfortran I get the following error messages.



gfortran randomsys1.f90 -L/usr/lib/lapack -llapack -L/usr/lib/libblas -lblas
/tmp/cclwtifh.o: In function `MAIN__':
randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
collect2: error: ld returned 1 exit status


or



gfortran randomsys1.f90 -llapack -lblas
/tmp/ccB1isEC.o: In function `MAIN__':
randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
collect2: error: ld returned 1 exit status


As per my understanding, it is the recommended way to link gfortran with lapack and blas (kindly refer to gfortran LAPACK “undefined reference” error). Thanks in advance for pointing out the correct way to compile the fortran code using gfortran.










share|improve this question




























    up vote
    0
    down vote

    favorite
    1












    I have installed LAPACK and BLAS from Synaptic package manager in Ubuntu.



    whereis libblas
    libblas: /usr/lib/libblas.so /usr/lib/libblas.a /usr/lib/libblas

    whereis liblapack
    liblapack: /usr/lib/liblapack.a /usr/lib/liblapack.so


    When I try to compile the randomsys1 example with gfortran I get the following error messages.



    gfortran randomsys1.f90 -L/usr/lib/lapack -llapack -L/usr/lib/libblas -lblas
    /tmp/cclwtifh.o: In function `MAIN__':
    randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
    collect2: error: ld returned 1 exit status


    or



    gfortran randomsys1.f90 -llapack -lblas
    /tmp/ccB1isEC.o: In function `MAIN__':
    randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
    collect2: error: ld returned 1 exit status


    As per my understanding, it is the recommended way to link gfortran with lapack and blas (kindly refer to gfortran LAPACK “undefined reference” error). Thanks in advance for pointing out the correct way to compile the fortran code using gfortran.










    share|improve this question


























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I have installed LAPACK and BLAS from Synaptic package manager in Ubuntu.



      whereis libblas
      libblas: /usr/lib/libblas.so /usr/lib/libblas.a /usr/lib/libblas

      whereis liblapack
      liblapack: /usr/lib/liblapack.a /usr/lib/liblapack.so


      When I try to compile the randomsys1 example with gfortran I get the following error messages.



      gfortran randomsys1.f90 -L/usr/lib/lapack -llapack -L/usr/lib/libblas -lblas
      /tmp/cclwtifh.o: In function `MAIN__':
      randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
      collect2: error: ld returned 1 exit status


      or



      gfortran randomsys1.f90 -llapack -lblas
      /tmp/ccB1isEC.o: In function `MAIN__':
      randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
      collect2: error: ld returned 1 exit status


      As per my understanding, it is the recommended way to link gfortran with lapack and blas (kindly refer to gfortran LAPACK “undefined reference” error). Thanks in advance for pointing out the correct way to compile the fortran code using gfortran.










      share|improve this question















      I have installed LAPACK and BLAS from Synaptic package manager in Ubuntu.



      whereis libblas
      libblas: /usr/lib/libblas.so /usr/lib/libblas.a /usr/lib/libblas

      whereis liblapack
      liblapack: /usr/lib/liblapack.a /usr/lib/liblapack.so


      When I try to compile the randomsys1 example with gfortran I get the following error messages.



      gfortran randomsys1.f90 -L/usr/lib/lapack -llapack -L/usr/lib/libblas -lblas
      /tmp/cclwtifh.o: In function `MAIN__':
      randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
      collect2: error: ld returned 1 exit status


      or



      gfortran randomsys1.f90 -llapack -lblas
      /tmp/ccB1isEC.o: In function `MAIN__':
      randomsys1.f90:(.text+0x12): undefined reference to `init_random_seed_'
      collect2: error: ld returned 1 exit status


      As per my understanding, it is the recommended way to link gfortran with lapack and blas (kindly refer to gfortran LAPACK “undefined reference” error). Thanks in advance for pointing out the correct way to compile the fortran code using gfortran.







      fortran gfortran lapack blas






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 23 '17 at 12:23









      Community

      11




      11










      asked Jan 26 '16 at 4:21









      Rajarshi

      32




      32
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Give this a try



          gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas


          I think you went one directory too far



          I wrote a program using the LAPACK eigensolver and here is how I successfully compiled it on my own computer. It was used to calculate modes of a spring-mass system.



          gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack


          This also works on my computer



          gfortran eigen.f90 -lblas -llapack


          I just tried both to verify.



          PS, now that you know how to compile, I think you need the subroutine init_random_seed in your program (goes after "contains" but before "end program"). This one is from google. No idea if it is what you need, your professor should be able to steer you correctly here.



          ! Initialize the random number generator using current time,
          ! so a new sequence of random numbers is generated each
          ! execution time.

          ! Taken from http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html

          SUBROUTINE init_random_seed()
          INTEGER :: i, n, clock
          INTEGER, DIMENSION(:), ALLOCATABLE :: seed

          CALL RANDOM_SEED(size = n)
          ALLOCATE(seed(n))

          CALL SYSTEM_CLOCK(COUNT=clock)

          seed = clock + 37 * (/ (i - 1, i = 1, n) /)
          CALL RANDOM_SEED(PUT = seed)

          print *, "Using random seed = ", seed
          print *, " "

          DEALLOCATE(seed)
          END SUBROUTINE





          share|improve this answer























          • Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
            – Rajarshi
            Jan 26 '16 at 16:42










          • The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
            – J.J. Hakala
            Jan 26 '16 at 17:15










          • @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
            – Mark S
            Jan 26 '16 at 20:27










          • @MarkS, sure. I have done it.
            – Rajarshi
            Jan 28 '16 at 3:53


















          up vote
          0
          down vote













          I had the same problem. I followed the recommendation above and
          it worked. Here's my working example batch file (it has to be executed
          in the cmd window):



          gfortran -c forkurs_evd.f90
          gfortran -o kurs_evd.exe kurs_evd.o charint.o -L/usr/lib -llapack -L/usr/lib -lblas
          kurs_evd.exe





          share|improve this answer










          New contributor




          Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















            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%2f35007006%2ferror-in-linking-gfortran-to-lapack-and-blas%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            Give this a try



            gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas


            I think you went one directory too far



            I wrote a program using the LAPACK eigensolver and here is how I successfully compiled it on my own computer. It was used to calculate modes of a spring-mass system.



            gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack


            This also works on my computer



            gfortran eigen.f90 -lblas -llapack


            I just tried both to verify.



            PS, now that you know how to compile, I think you need the subroutine init_random_seed in your program (goes after "contains" but before "end program"). This one is from google. No idea if it is what you need, your professor should be able to steer you correctly here.



            ! Initialize the random number generator using current time,
            ! so a new sequence of random numbers is generated each
            ! execution time.

            ! Taken from http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html

            SUBROUTINE init_random_seed()
            INTEGER :: i, n, clock
            INTEGER, DIMENSION(:), ALLOCATABLE :: seed

            CALL RANDOM_SEED(size = n)
            ALLOCATE(seed(n))

            CALL SYSTEM_CLOCK(COUNT=clock)

            seed = clock + 37 * (/ (i - 1, i = 1, n) /)
            CALL RANDOM_SEED(PUT = seed)

            print *, "Using random seed = ", seed
            print *, " "

            DEALLOCATE(seed)
            END SUBROUTINE





            share|improve this answer























            • Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
              – Rajarshi
              Jan 26 '16 at 16:42










            • The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
              – J.J. Hakala
              Jan 26 '16 at 17:15










            • @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
              – Mark S
              Jan 26 '16 at 20:27










            • @MarkS, sure. I have done it.
              – Rajarshi
              Jan 28 '16 at 3:53















            up vote
            1
            down vote



            accepted










            Give this a try



            gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas


            I think you went one directory too far



            I wrote a program using the LAPACK eigensolver and here is how I successfully compiled it on my own computer. It was used to calculate modes of a spring-mass system.



            gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack


            This also works on my computer



            gfortran eigen.f90 -lblas -llapack


            I just tried both to verify.



            PS, now that you know how to compile, I think you need the subroutine init_random_seed in your program (goes after "contains" but before "end program"). This one is from google. No idea if it is what you need, your professor should be able to steer you correctly here.



            ! Initialize the random number generator using current time,
            ! so a new sequence of random numbers is generated each
            ! execution time.

            ! Taken from http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html

            SUBROUTINE init_random_seed()
            INTEGER :: i, n, clock
            INTEGER, DIMENSION(:), ALLOCATABLE :: seed

            CALL RANDOM_SEED(size = n)
            ALLOCATE(seed(n))

            CALL SYSTEM_CLOCK(COUNT=clock)

            seed = clock + 37 * (/ (i - 1, i = 1, n) /)
            CALL RANDOM_SEED(PUT = seed)

            print *, "Using random seed = ", seed
            print *, " "

            DEALLOCATE(seed)
            END SUBROUTINE





            share|improve this answer























            • Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
              – Rajarshi
              Jan 26 '16 at 16:42










            • The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
              – J.J. Hakala
              Jan 26 '16 at 17:15










            • @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
              – Mark S
              Jan 26 '16 at 20:27










            • @MarkS, sure. I have done it.
              – Rajarshi
              Jan 28 '16 at 3:53













            up vote
            1
            down vote



            accepted







            up vote
            1
            down vote



            accepted






            Give this a try



            gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas


            I think you went one directory too far



            I wrote a program using the LAPACK eigensolver and here is how I successfully compiled it on my own computer. It was used to calculate modes of a spring-mass system.



            gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack


            This also works on my computer



            gfortran eigen.f90 -lblas -llapack


            I just tried both to verify.



            PS, now that you know how to compile, I think you need the subroutine init_random_seed in your program (goes after "contains" but before "end program"). This one is from google. No idea if it is what you need, your professor should be able to steer you correctly here.



            ! Initialize the random number generator using current time,
            ! so a new sequence of random numbers is generated each
            ! execution time.

            ! Taken from http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html

            SUBROUTINE init_random_seed()
            INTEGER :: i, n, clock
            INTEGER, DIMENSION(:), ALLOCATABLE :: seed

            CALL RANDOM_SEED(size = n)
            ALLOCATE(seed(n))

            CALL SYSTEM_CLOCK(COUNT=clock)

            seed = clock + 37 * (/ (i - 1, i = 1, n) /)
            CALL RANDOM_SEED(PUT = seed)

            print *, "Using random seed = ", seed
            print *, " "

            DEALLOCATE(seed)
            END SUBROUTINE





            share|improve this answer














            Give this a try



            gfortran randomsys1.f90 -L/usr/lib -llapack -L/usr/lib -lblas


            I think you went one directory too far



            I wrote a program using the LAPACK eigensolver and here is how I successfully compiled it on my own computer. It was used to calculate modes of a spring-mass system.



            gfortran eigen.f90 -L/usr/local/lib -lblas -L/usr/local/lib -llapack


            This also works on my computer



            gfortran eigen.f90 -lblas -llapack


            I just tried both to verify.



            PS, now that you know how to compile, I think you need the subroutine init_random_seed in your program (goes after "contains" but before "end program"). This one is from google. No idea if it is what you need, your professor should be able to steer you correctly here.



            ! Initialize the random number generator using current time,
            ! so a new sequence of random numbers is generated each
            ! execution time.

            ! Taken from http://gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html

            SUBROUTINE init_random_seed()
            INTEGER :: i, n, clock
            INTEGER, DIMENSION(:), ALLOCATABLE :: seed

            CALL RANDOM_SEED(size = n)
            ALLOCATE(seed(n))

            CALL SYSTEM_CLOCK(COUNT=clock)

            seed = clock + 37 * (/ (i - 1, i = 1, n) /)
            CALL RANDOM_SEED(PUT = seed)

            print *, "Using random seed = ", seed
            print *, " "

            DEALLOCATE(seed)
            END SUBROUTINE






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jan 26 '16 at 5:29

























            answered Jan 26 '16 at 5:01









            Mark S

            1468




            1468












            • Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
              – Rajarshi
              Jan 26 '16 at 16:42










            • The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
              – J.J. Hakala
              Jan 26 '16 at 17:15










            • @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
              – Mark S
              Jan 26 '16 at 20:27










            • @MarkS, sure. I have done it.
              – Rajarshi
              Jan 28 '16 at 3:53


















            • Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
              – Rajarshi
              Jan 26 '16 at 16:42










            • The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
              – J.J. Hakala
              Jan 26 '16 at 17:15










            • @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
              – Mark S
              Jan 26 '16 at 20:27










            • @MarkS, sure. I have done it.
              – Rajarshi
              Jan 28 '16 at 3:53
















            Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
            – Rajarshi
            Jan 26 '16 at 16:42




            Thank you so much! You have rightly pointed out that init_random_seed subroutine was missing. After including the subroutine you provided, I could compile it with the command gfortran randomsys1.f90 -lblas -llapack.
            – Rajarshi
            Jan 26 '16 at 16:42












            The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
            – J.J. Hakala
            Jan 26 '16 at 17:15




            The code does not seem to match what is now in gcc.gnu.org/onlinedocs/gfortran/RANDOM_005fSEED.html, maybe there has been an update?
            – J.J. Hakala
            Jan 26 '16 at 17:15












            @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
            – Mark S
            Jan 26 '16 at 20:27




            @Rajarshi, can you officially accept my answer (top left of answer)? I am on a mission for more points!
            – Mark S
            Jan 26 '16 at 20:27












            @MarkS, sure. I have done it.
            – Rajarshi
            Jan 28 '16 at 3:53




            @MarkS, sure. I have done it.
            – Rajarshi
            Jan 28 '16 at 3:53












            up vote
            0
            down vote













            I had the same problem. I followed the recommendation above and
            it worked. Here's my working example batch file (it has to be executed
            in the cmd window):



            gfortran -c forkurs_evd.f90
            gfortran -o kurs_evd.exe kurs_evd.o charint.o -L/usr/lib -llapack -L/usr/lib -lblas
            kurs_evd.exe





            share|improve this answer










            New contributor




            Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.






















              up vote
              0
              down vote













              I had the same problem. I followed the recommendation above and
              it worked. Here's my working example batch file (it has to be executed
              in the cmd window):



              gfortran -c forkurs_evd.f90
              gfortran -o kurs_evd.exe kurs_evd.o charint.o -L/usr/lib -llapack -L/usr/lib -lblas
              kurs_evd.exe





              share|improve this answer










              New contributor




              Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.




















                up vote
                0
                down vote










                up vote
                0
                down vote









                I had the same problem. I followed the recommendation above and
                it worked. Here's my working example batch file (it has to be executed
                in the cmd window):



                gfortran -c forkurs_evd.f90
                gfortran -o kurs_evd.exe kurs_evd.o charint.o -L/usr/lib -llapack -L/usr/lib -lblas
                kurs_evd.exe





                share|improve this answer










                New contributor




                Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                I had the same problem. I followed the recommendation above and
                it worked. Here's my working example batch file (it has to be executed
                in the cmd window):



                gfortran -c forkurs_evd.f90
                gfortran -o kurs_evd.exe kurs_evd.o charint.o -L/usr/lib -llapack -L/usr/lib -lblas
                kurs_evd.exe






                share|improve this answer










                New contributor




                Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                share|improve this answer



                share|improve this answer








                edited yesterday









                Lorelorelore

                1,36811122




                1,36811122






                New contributor




                Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.









                answered yesterday









                Peter Dr. Strobach

                1




                1




                New contributor




                Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





                New contributor





                Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






                Peter Dr. Strobach is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f35007006%2ferror-in-linking-gfortran-to-lapack-and-blas%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

                    Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

                    Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

                    A Topological Invariant for $pi_3(U(n))$