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. use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler
Forum Updated to NodeBB v4.3 + New Features

use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.5k Views 1 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.
  • T Offline
    T Offline
    tudiudiu
    wrote on 6 Jul 2018, 11:58 last edited by
    #1

    Hello Everyone:
    I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.

    Looking forward to your reply & Thanks again for your patience
    tudiudiu

    K A T 3 Replies Last reply 6 Jul 2018, 14:21
    0
    • T tudiudiu
      6 Jul 2018, 11:58

      Hello Everyone:
      I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.

      Looking forward to your reply & Thanks again for your patience
      tudiudiu

      K Offline
      K Offline
      koahnig
      wrote on 6 Jul 2018, 14:21 last edited by
      #2

      @tudiudiu

      How were the Qt libraries compiled when you combine them with the 64bit compiled FORTRAN?

      IIRC the question might if the memory model is the same for 64bit FORTRAN and C++ compiled with the same MinGW suite.

      IMHO it is at the day's end not an issue of Qt, but more something with the compilers and the memory handling there.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      4
      • T tudiudiu
        6 Jul 2018, 11:58

        Hello Everyone:
        I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.

        Looking forward to your reply & Thanks again for your patience
        tudiudiu

        A Offline
        A Offline
        aha_1980
        Lifetime Qt Champion
        wrote on 6 Jul 2018, 14:28 last edited by aha_1980 7 Jun 2018, 16:51
        #3

        @tudiudiu, as @koahnig already said this is more likely a compiler problem. As you already noted, it may be pointer related. 64 bit C++ compiler operate with 64 bit pointers, while 32 bit compilers use 32 bit pointers.

        so the question: how do you combine your C++ and Fortran code? and which compiler do you use to compile fortran? do you compile Fortran to 64 bit also?

        Qt has to stay free or it will die.

        1 Reply Last reply
        3
        • T tudiudiu
          6 Jul 2018, 11:58

          Hello Everyone:
          I have recently met a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every value in my array is "NAN".I have doubt about the pointer is beyond the boundary of the array when the matrix is transferring from Qt to Fortran.My operating system is X86_64 Windows7.I really really what to know what is the reason for that problem and how to solve this fatal problem.

          Looking forward to your reply & Thanks again for your patience
          tudiudiu

          T Offline
          T Offline
          tudiudiu
          wrote on 7 Jul 2018, 00:33 last edited by
          #4

          @tudiudiu said in use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler:

          et a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every

          Hi~~~@koahnig @aha_1980
          In my Qt .pro file,the combine style is remarked as “lib += lgfortran,source += /abc.f90”.
          In my Fortran file, the function is named as "sub(arg1,arg2,arg3......argN)"
          In my main function file,Remark : extern "C" {void sub_(int *m, int *n, float x[], float fvec[], int *iflag);}
          Then the Fortran's Subroutine is used by Qt as an external void function so that the compiler could compile the Qt & fortran at the same time. In my Qt Creator Edit , I have configured 2 kind of compile chain kit, MingW32 & MingW64. Even if the source code is same, but I can choose one compiler i need at one time(MingW32 or MingW64).

          As you already noted, the problem has something to do with the memory handling and pointer length.
          The argument function in Fortran expect a 32-bit pointer transferred by Qt , but for 64bit compiler, the length of pointer is 64-bit. So I am planning to rewrite the Fortran code , for example "Integer *4 -> Integer 8, Real4 ->Double *8". I'm not sure whether it would work or not. I will reply to you @koahnig @aha_1980 as soon as i get the result.

          Really Appreciate for your guide And thanks again ~~~

          tudiudiu

          A 1 Reply Last reply 7 Jul 2018, 06:05
          1
          • T tudiudiu
            7 Jul 2018, 00:33

            @tudiudiu said in use a function written by Fortran source code in Qt,the result of function is right by 32bit compiler,the result is wrong by 64bit compiler:

            et a strange problem about Qt&Fortran integrating program.In my Desktop App,the main function frame is written by Qt, I need a calculated function whose source code was written by Fortran,but not a .dll lib file.And I confirm that all the source code (Qt&Fortran) are right,The program could be compiled normally and run in my computer.I use 2 kind of compilers.The result of function which was compiled by 32-bit GNU-Mingw is right, I can get what I expected. However, when the code is compiled by 64-bit GNU-Mingw, Although the program can run , the result of calculated function is wrong. I check out the array matrix by qDebug, every

            Hi~~~@koahnig @aha_1980
            In my Qt .pro file,the combine style is remarked as “lib += lgfortran,source += /abc.f90”.
            In my Fortran file, the function is named as "sub(arg1,arg2,arg3......argN)"
            In my main function file,Remark : extern "C" {void sub_(int *m, int *n, float x[], float fvec[], int *iflag);}
            Then the Fortran's Subroutine is used by Qt as an external void function so that the compiler could compile the Qt & fortran at the same time. In my Qt Creator Edit , I have configured 2 kind of compile chain kit, MingW32 & MingW64. Even if the source code is same, but I can choose one compiler i need at one time(MingW32 or MingW64).

            As you already noted, the problem has something to do with the memory handling and pointer length.
            The argument function in Fortran expect a 32-bit pointer transferred by Qt , but for 64bit compiler, the length of pointer is 64-bit. So I am planning to rewrite the Fortran code , for example "Integer *4 -> Integer 8, Real4 ->Double *8". I'm not sure whether it would work or not. I will reply to you @koahnig @aha_1980 as soon as i get the result.

            Really Appreciate for your guide And thanks again ~~~

            tudiudiu

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 7 Jul 2018, 06:05 last edited by
            #5

            Hi @tudiudiu

            I'm sorry, but I have absolutely no Fortran knowledge.

            So if I understand you correctly, you have an entry SOURCES += abc.f90 in your .profile. That means, abc.f90 is your Fortran source file, correct?

            That means, qmake generates a Makefile which calls the Fortran compiler, correct too?

            So have you checked that the correct Fortran compiler (64 bit) is called for your 64 bit code?

            Regards

            Qt has to stay free or it will die.

            K 1 Reply Last reply 7 Jul 2018, 09:24
            1
            • A aha_1980
              7 Jul 2018, 06:05

              Hi @tudiudiu

              I'm sorry, but I have absolutely no Fortran knowledge.

              So if I understand you correctly, you have an entry SOURCES += abc.f90 in your .profile. That means, abc.f90 is your Fortran source file, correct?

              That means, qmake generates a Makefile which calls the Fortran compiler, correct too?

              So have you checked that the correct Fortran compiler (64 bit) is called for your 64 bit code?

              Regards

              K Offline
              K Offline
              koahnig
              wrote on 7 Jul 2018, 09:24 last edited by
              #6

              @aha_1980

              IMHO the lack of Fortran knowledge is actually an advantage. I started out with Fortran very long ago and have pushed all knowledge to the back where the cobwebs reside ;)

              More seriously. As @aha_1980 already mentions did you check that you are using 64 bit compilers in both cases?
              Basically I would suggest that you are using the same MinGW compiler for both Fortran and C++.

              You did not give information of the library you are using from Fortran. I am typically going the route to convert Fortran to C/C++ and compile. However, that might be only an option with smaller libraries, since I was substituting the few Fortran emulating library calls with C/C++ calls when required.

              Vote the answer(s) that helped you to solve your issue(s)

              1 Reply Last reply
              3
              • T Offline
                T Offline
                tudiudiu
                wrote on 8 Jul 2018, 03:01 last edited by
                #7

                @aha_1980 @koahnig
                Hi~my friends,Thanks for your kindly help, And i have been trying to find this bug as the advice you give.

                First of all, I check the compilers to make sure there is only an effective tool chain. All of the source code were transferred to another machine(only with MingW64) to compile , The Result is still "NAN".However ,When the source code were transferred to a machine(only with MingW32) to compile, the Result is acceptable.

                Secondly,I attempted to check whether there are a few lib(32bit dynamic or static) in Fortran code. At last, The result is that there is not other lib at all, The target function is written by pure Fortran format.

                Thirdly, I rewrite part of the Fortran code with regarding to the variable declaration so that the length of variable could match the length of pointer in 64-bit system . For example "Integer *4 -> Integer 8, Real4 ->Double *8". But it doesn't work.

                Finally, I change another new simple function ,Transfer a 2-Dimension matrix from Fortran to Qt, The result is totally correct.

                So the bug seem to be nothing to do with the compilers .
                I think the Fortran code i got from my company is wrong. I can't not imagine my colleague take that kind of stupid mistake , What makes me unexpected more is my boss have checked and give him "PASS".=_=|||

                I feel so apologetic for my fault.I should have think about this problem.
                Sincerely gratitude for your help again.@aha_1980 @koahnig

                Regards
                tudiudiu

                1 Reply Last reply
                2

                1/7

                6 Jul 2018, 11:58

                • Login

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