Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Independent Developers
  4. math function failing
QtWS25 Last Chance

math function failing

Scheduled Pinned Locked Moved Unsolved Independent Developers
18 Posts 4 Posters 2.5k Views
  • 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.
  • G Offline
    G Offline
    goswami
    wrote on 14 Aug 2022, 06:57 last edited by
    #1

    I have got a project sample from one cmake user. When I am trying to build the same in my PC I am getting lots of error over undefined reference of math function defined in math.h file. A sample as " :-1: error:-----FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsblock5.c:342: undefined reference to `floor'".
    Can anybody throw some light why the same is happening despite math.h is included in the same file?
    I also require a bit of help on community help over Qt. I am only getting mail as help can be extended on commercial license. I am pursuing Qt purely for self education. Is there anyway to know what to do if no response is given in the forum?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 14 Aug 2022, 15:32 last edited by mrjj
      #2

      Hi
      -Can anybody throw some light why the same is happening despite math.h is included in the same file?

      Well if you are not on the same platform, it can be that Cmake cant find the math lib to link against.

      • . Is there anyway to know what to do if no response is given in the forum?

      There are other coding places to ask also. Like StackOverflow.
      But make sure you write good questions as it's impossible to help if clear information is not
      provided.

      But normally we do answer most questions here :)

      G 2 Replies Last reply 15 Aug 2022, 10:57
      1
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 14 Aug 2022, 18:17 last edited by
        #3

        Hi,

        I would say that you are missing std:: before your floor calls.

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

        G 1 Reply Last reply 15 Aug 2022, 11:17
        1
        • M mrjj
          14 Aug 2022, 15:32

          Hi
          -Can anybody throw some light why the same is happening despite math.h is included in the same file?

          Well if you are not on the same platform, it can be that Cmake cant find the math lib to link against.

          • . Is there anyway to know what to do if no response is given in the forum?

          There are other coding places to ask also. Like StackOverflow.
          But make sure you write good questions as it's impossible to help if clear information is not
          provided.

          But normally we do answer most questions here :)

          G Offline
          G Offline
          goswami
          wrote on 15 Aug 2022, 10:57 last edited by
          #4

          @mrjj Thank you for taking up my call. I tried with a small program with math.h and cmake. It is working alright. Hence not sure why same is failing for the FMI one.

          1 Reply Last reply
          0
          • S SGaist
            14 Aug 2022, 18:17

            Hi,

            I would say that you are missing std:: before your floor calls.

            G Offline
            G Offline
            goswami
            wrote on 15 Aug 2022, 11:17 last edited by
            #5

            @SGaist The code is auto generated by a tool called Dymola. They insist for Visual Studio but I wanted to try on Qt Creator. It is appearing linking failure. The error message in Qt Creator is as below
            :-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in function ModelicaInternal_temporaryFileName': :-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in function Mat_VarDelete':
            :-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in function divideDymola': /home/skgoswami/Desktop/DymolaTest/FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsutil.h:789: error: undefined reference to floor'
            :-1: error: /home/skgoswami/Desktop/DymolaTest/FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsutil.h:789: undefined reference to ceil' :-1: error: CMakeFiles/app.dir/Bool_Multi/sources/all.c.o: in function modulusDymola':
            /home/skgoswami/Desktop/DymolaTest/FMI_Stdalone_Bool_multi_proj/Bool_Multi/sources/dsutil.h:792: error: undefined reference to `floor'

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 15 Aug 2022, 12:33 last edited by SGaist
              #6

              Visual Studio designate both the IDE and the set of tools, Qt Creator is just an IDE.

              But it looks like you are working on Linux so can you explain your environment ?

              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
              • G Offline
                G Offline
                goswami
                wrote on 15 Aug 2022, 13:30 last edited by
                #7

                I exactly could not understand what you meant by environment. Yes mine is ubuntu 20.04.4, Qt creator 7.0.2, cmake 3.21.1. gcc by default 64bit. The builder is being used 'ninja' by default. I found users faced problem with math.h linking. However I am not getting any problem if I make a simple program as reported by those users. However error is same undefined reference. Incidentally the application is C and hence std:: is not acceptable. I am better providing the content of CMakeLists.txt file for your ready reference below

                cmake_minimum_required (VERSION 3.7)
                set (MODEL_NAME Bool_Multi)
                project (Bool_Multi LANGUAGES C)
                add_executable(app
                include/fmi2Functions.h
                include/fmi2FunctionTypes.h
                include/fmi2TypesPlatform.h
                src/bool_multi.c
                Bool_Multi/sources/all.c
                )
                target_include_directories(app PUBLIC
                include
                Bool_Multi/sources
                )

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 15 Aug 2022, 18:37 last edited by
                  #8

                  From the looks of it, you are not linking to the math library.

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

                  G 1 Reply Last reply 16 Aug 2022, 06:10
                  0
                  • S SGaist
                    15 Aug 2022, 18:37

                    From the looks of it, you are not linking to the math library.

                    G Offline
                    G Offline
                    goswami
                    wrote on 16 Aug 2022, 06:10 last edited by
                    #9

                    @SGaist Yes but why so is not clear. Single file with math.h is working OK. Where the linker related setting and how it can be fixed is my question.

                    1 Reply Last reply
                    0
                    • M mrjj
                      14 Aug 2022, 15:32

                      Hi
                      -Can anybody throw some light why the same is happening despite math.h is included in the same file?

                      Well if you are not on the same platform, it can be that Cmake cant find the math lib to link against.

                      • . Is there anyway to know what to do if no response is given in the forum?

                      There are other coding places to ask also. Like StackOverflow.
                      But make sure you write good questions as it's impossible to help if clear information is not
                      provided.

                      But normally we do answer most questions here :)

                      G Offline
                      G Offline
                      goswami
                      wrote on 16 Aug 2022, 06:24 last edited by
                      #10

                      @mrjj it is linking time problem undestood but do not know how to fix it in Qt. Single file with #include<math.h> is working alright. Pl. advise if any other sources to explore for the solution.

                      J 1 Reply Last reply 16 Aug 2022, 07:41
                      0
                      • G goswami
                        16 Aug 2022, 06:24

                        @mrjj it is linking time problem undestood but do not know how to fix it in Qt. Single file with #include<math.h> is working alright. Pl. advise if any other sources to explore for the solution.

                        J Offline
                        J Offline
                        JonB
                        wrote on 16 Aug 2022, 07:41 last edited by
                        #11

                        @goswami
                        Please show the linker line being executed. So far as I am aware, linking with math library is achieved via -lm option.

                        G 1 Reply Last reply 16 Aug 2022, 13:08
                        2
                        • J JonB
                          16 Aug 2022, 07:41

                          @goswami
                          Please show the linker line being executed. So far as I am aware, linking with math library is achieved via -lm option.

                          G Offline
                          G Offline
                          goswami
                          wrote on 16 Aug 2022, 13:08 last edited by
                          #12

                          @JonB I am using Qt IDE with cmake for building. Following code is working alright
                          #include <stdio.h>
                          #include <math.h>
                          int main()
                          {
                          printf("Hello World!=%f\n",pow(2.0,2.0));
                          return 0;
                          }

                          And CMakeLists.txt content is as below
                          cmake_minimum_required(VERSION 3.5)
                          project(untitled1 LANGUAGES C)
                          add_executable(untitled1 main.c)

                          I do not know how to check linker option in Qt IDE. This is reasonably big project and impossible to go for command line building.

                          J 1 Reply Last reply 16 Aug 2022, 13:11
                          0
                          • G goswami
                            16 Aug 2022, 13:08

                            @JonB I am using Qt IDE with cmake for building. Following code is working alright
                            #include <stdio.h>
                            #include <math.h>
                            int main()
                            {
                            printf("Hello World!=%f\n",pow(2.0,2.0));
                            return 0;
                            }

                            And CMakeLists.txt content is as below
                            cmake_minimum_required(VERSION 3.5)
                            project(untitled1 LANGUAGES C)
                            add_executable(untitled1 main.c)

                            I do not know how to check linker option in Qt IDE. This is reasonably big project and impossible to go for command line building.

                            J Offline
                            J Offline
                            JonB
                            wrote on 16 Aug 2022, 13:11 last edited by
                            #13

                            @goswami said in math function failing:

                            I do not know how to check linker option in Qt IDE

                            Did you try looking in the Build Output pane? I don't know, that would be my guess. And I don't know about cmake so I'll leave you with others to respond.

                            G 1 Reply Last reply 16 Aug 2022, 13:20
                            0
                            • J JonB
                              16 Aug 2022, 13:11

                              @goswami said in math function failing:

                              I do not know how to check linker option in Qt IDE

                              Did you try looking in the Build Output pane? I don't know, that would be my guess. And I don't know about cmake so I'll leave you with others to respond.

                              G Offline
                              G Offline
                              goswami
                              wrote on 16 Aug 2022, 13:20 last edited by
                              #14

                              @JonB Thanks for trying to help.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 16 Aug 2022, 17:34 last edited by
                                #15
                                target_link_libraries(untitled1 m)
                                

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

                                G 1 Reply Last reply 18 Aug 2022, 12:58
                                2
                                • S SGaist
                                  16 Aug 2022, 17:34
                                  target_link_libraries(untitled1 m)
                                  
                                  G Offline
                                  G Offline
                                  goswami
                                  wrote on 18 Aug 2022, 12:58 last edited by
                                  #16

                                  @SGaist said in math function failing:

                                  target_link_libraries(untitled1 m)

                                  Many thanks all math.h related errors have gone and the application is giving output. Can you throw some light why the same is not failing when only one file with math.h include is there? Another as it is appearing all #include of libraries are not creating problem. Is it system dependant viz. may compile in one environment but fail in somewhere?
                                  I am really grateful over the efforts you have put to help me out of this crisis which became a serious bottleneck for progress to next stage.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 18 Aug 2022, 18:29 last edited by
                                    #17

                                    It depends on the library and what is used of them.

                                    Some are header only, some are template based so it really depends on what you use from these and how they are implemented. It's usually not tied to a specific OS.

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

                                    G 1 Reply Last reply 21 Aug 2022, 10:24
                                    0
                                    • S SGaist
                                      18 Aug 2022, 18:29

                                      It depends on the library and what is used of them.

                                      Some are header only, some are template based so it really depends on what you use from these and how they are implemented. It's usually not tied to a specific OS.

                                      G Offline
                                      G Offline
                                      goswami
                                      wrote on 21 Aug 2022, 10:24 last edited by
                                      #18

                                      @SGaist Thank you very much for updating me.

                                      1 Reply Last reply
                                      0

                                      3/18

                                      14 Aug 2022, 18:17

                                      topic:navigator.unread, 15
                                      • Login

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