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. Undefined refence to "main"

Undefined refence to "main"

Scheduled Pinned Locked Moved Solved General and Desktop
35 Posts 5 Posters 7.8k 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.
  • R Offline
    R Offline
    R.griset
    wrote on 26 Dec 2019, 11:31 last edited by
    #13

    Ok thanks to your advices I switched the Qt version used to build from 4 to 5 (this code has been developed with QT5 )

    However I'm still ahving the error

    41ccedf9-a7ba-4031-a81d-519314183e13-image.png
    c6f2724e-a9ab-4774-b95c-e30996e41c41-image.png

    1 Reply Last reply
    0
    • R Offline
      R Offline
      R.griset
      wrote on 26 Dec 2019, 12:29 last edited by
      #14

      I think the error probably comes from the fact qmake is called with -qt4 option but I can't figure out how to change it

      8e86c934-caa4-45c0-acc0-449e48777669-image.png

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 26 Dec 2019, 12:35 last edited by
        #15

        Select the correct qmake for the correct Qt5 kit under 'Qt versions'

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        1 Reply Last reply
        1
        • R Offline
          R Offline
          R.griset
          wrote on 26 Dec 2019, 12:44 last edited by
          #16

          Hello Christian Ehrlicher and thanks for helping

          Ok i changed the kit but now i'm getting back to my initial issue which I encountered outside of Qt creator : the undefined reference to main :(

          13:35:55: Running steps for project anchorage...
          13:35:55: Configuration unchanged, skipping qmake step.
          13:35:55: Starting: "/usr/bin/make"
          cd src/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /home/d07876/Desktop/Ancrage/Code\ interface\ graphique\ ancrage/UI_11_05/src/src.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && /usr/bin/make -f Makefile
          make[1]: Entering directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
          g++ -m64 -o src heuristics.o longest_paths.o manual_modification.o metaheuristics.o resource_flow_computation.o resource_flow_modifications.o data_models.o data_structures.o resource_flow.o parsing.o writing.o central_widget.o central_widget_solution_tab.o gantt_view.o mainwindow.o parameters_bar.o parameters_edition_dialog.o resource_view.o sidebar.o sidebar_list.o solution_pool_view.o moc_data_models.o moc_central_widget.o moc_central_widget_solution_tab.o moc_gantt_view.o moc_mainwindow.o moc_parameters_bar.o moc_parameters_edition_dialog.o moc_resource_view.o moc_sidebar.o moc_sidebar_list.o moc_solution_pool_view.o -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
          /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function _start': (.text+0x20): undefined reference to main'
          Makefile:228: recipe for target 'src' failed
          make[1]: Leaving directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
          Makefile:43: recipe for target 'sub-src-make_first' failed
          collect2: error: ld returned 1 exit status
          make[1]: *** [src] Error 1
          make: *** [sub-src-make_first] Error 2
          13:35:56: The process "/usr/bin/make" exited with code 2.
          Error while building/deploying project anchorage (kit: QT5)
          When executing step "Make"
          13:35:56: Elapsed time: 00:01.

          A 1 Reply Last reply 26 Dec 2019, 12:50
          0
          • R R.griset
            26 Dec 2019, 12:44

            Hello Christian Ehrlicher and thanks for helping

            Ok i changed the kit but now i'm getting back to my initial issue which I encountered outside of Qt creator : the undefined reference to main :(

            13:35:55: Running steps for project anchorage...
            13:35:55: Configuration unchanged, skipping qmake step.
            13:35:55: Starting: "/usr/bin/make"
            cd src/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /home/d07876/Desktop/Ancrage/Code\ interface\ graphique\ ancrage/UI_11_05/src/src.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && /usr/bin/make -f Makefile
            make[1]: Entering directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
            g++ -m64 -o src heuristics.o longest_paths.o manual_modification.o metaheuristics.o resource_flow_computation.o resource_flow_modifications.o data_models.o data_structures.o resource_flow.o parsing.o writing.o central_widget.o central_widget_solution_tab.o gantt_view.o mainwindow.o parameters_bar.o parameters_edition_dialog.o resource_view.o sidebar.o sidebar_list.o solution_pool_view.o moc_data_models.o moc_central_widget.o moc_central_widget_solution_tab.o moc_gantt_view.o moc_mainwindow.o moc_parameters_bar.o moc_parameters_edition_dialog.o moc_resource_view.o moc_sidebar.o moc_sidebar_list.o moc_solution_pool_view.o -L/usr/X11R6/lib64 -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
            /usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function _start': (.text+0x20): undefined reference to main'
            Makefile:228: recipe for target 'src' failed
            make[1]: Leaving directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/src'
            Makefile:43: recipe for target 'sub-src-make_first' failed
            collect2: error: ld returned 1 exit status
            make[1]: *** [src] Error 1
            make: *** [sub-src-make_first] Error 2
            13:35:56: The process "/usr/bin/make" exited with code 2.
            Error while building/deploying project anchorage (kit: QT5)
            When executing step "Make"
            13:35:56: Elapsed time: 00:01.

            A Offline
            A Offline
            aha_1980
            Lifetime Qt Champion
            wrote on 26 Dec 2019, 12:50 last edited by
            #17

            @R-griset please remove all build artifacts and build again.

            Regards

            Qt has to stay free or it will die.

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on 26 Dec 2019, 12:51 last edited by
              #18

              In your src.pro you tell qmake that you want to build an application but you do not provide a main() function there (I would guess)

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              R 1 Reply Last reply 26 Dec 2019, 12:55
              0
              • C Christian Ehrlicher
                26 Dec 2019, 12:51

                In your src.pro you tell qmake that you want to build an application but you do not provide a main() function there (I would guess)

                R Offline
                R Offline
                R.griset
                wrote on 26 Dec 2019, 12:55 last edited by
                #19

                @Christian-Ehrlicher but this exact code work perfectly on an other computer so there should be a setting which doesn't need a main function there

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 26 Dec 2019, 13:23 last edited by
                  #20

                  @R-griset said in Undefined refence to "main":

                  so there should be a setting which doesn't need a main function there

                  Yes, don't tell qmake that you want to create an application... an application needs a main.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  R 1 Reply Last reply 26 Dec 2019, 14:02
                  0
                  • R Offline
                    R Offline
                    R.griset
                    wrote on 26 Dec 2019, 13:51 last edited by
                    #21

                    When I do so i.e replacing TEMPLATE = app by TEMPLATE = lib in the src.pro file , it leads to other errors.

                    In an other computer it work with TEMPLATE = app without this "undefined reference to main" issue so I'm looking for an explanation about how QT creator build the project in the other computer.

                    1 Reply Last reply
                    0
                    • C Christian Ehrlicher
                      26 Dec 2019, 13:23

                      @R-griset said in Undefined refence to "main":

                      so there should be a setting which doesn't need a main function there

                      Yes, don't tell qmake that you want to create an application... an application needs a main.

                      R Offline
                      R Offline
                      R.griset
                      wrote on 26 Dec 2019, 14:02 last edited by
                      #22

                      @Christian-Ehrlicher when I define src as a library I get

                      /usr/bin/ld: cannot find -lmyapp
                      Makefile:127: recipe for target 'app' failed
                      make[1]: Leaving directory '/home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/app'
                      Makefile:68: recipe for target 'sub-app-make_first' failed
                      collect2: error: ld returned 1 exit status
                      make[1]: *** [app] Error 1
                      make: *** [sub-app-make_first] Error 2
                      15:01:17: The process "/usr/bin/make" exited with code 2.
                      Error while building/deploying project anchorage (kit: QT5)
                      When executing step "Make"

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        R.griset
                        wrote on 26 Dec 2019, 14:12 last edited by
                        #23

                        it seems to come from the fact that line

                        "LIBS += -L../src -lmyapp" in app.pro file is not recognize when src.pro is define as a library

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 26 Dec 2019, 18:50 last edited by
                          #24

                          As already pointed out earlier, your project, as it is can not compile.

                          As for your LIBS statement, the library is generated in the shadow build folder, not in your sources where you are pointing it to. Use the OUT_PWD variable as starting folder.

                          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
                          • R Offline
                            R Offline
                            R.griset
                            wrote on 27 Dec 2019, 09:46 last edited by
                            #25

                            Hello SGaist and merry Christmas,

                            Thanks again for your help but once again I can't figure out what you want me to do exactly. So here is how I understood your advice :

                            • As you told me in one of your first post I need to set "TEMPLATE = lib" instead of "TEMPLATE = app" in my src.pro file
                            • Now when I compile the compiler doesn't find -lmyapp (by the way I don't know if "myapp" is a generic name ) because in my app.pro file I point to ../src in line "LIBS += -L../src -lmyapp"
                            • Instead of ../src I tried $OUT_PWD or $OUT_PWD/src but the compiler still doesn't find -lmyapp :(

                            I guess I didn't understand your post

                            A 1 Reply Last reply 27 Dec 2019, 10:09
                            0
                            • R R.griset
                              27 Dec 2019, 09:46

                              Hello SGaist and merry Christmas,

                              Thanks again for your help but once again I can't figure out what you want me to do exactly. So here is how I understood your advice :

                              • As you told me in one of your first post I need to set "TEMPLATE = lib" instead of "TEMPLATE = app" in my src.pro file
                              • Now when I compile the compiler doesn't find -lmyapp (by the way I don't know if "myapp" is a generic name ) because in my app.pro file I point to ../src in line "LIBS += -L../src -lmyapp"
                              • Instead of ../src I tried $OUT_PWD or $OUT_PWD/src but the compiler still doesn't find -lmyapp :(

                              I guess I didn't understand your post

                              A Offline
                              A Offline
                              aha_1980
                              Lifetime Qt Champion
                              wrote on 27 Dec 2019, 10:09 last edited by
                              #26

                              @R-griset said in Undefined refence to "main":

                              As you told me in one of your first post I need to set "TEMPLATE = lib" instead of "TEMPLATE = app" in my src.pro file

                              If you want to build a library, use the former one, if you want to build a program, use "app".

                              Now when I compile the compiler doesn't find -lmyapp (by the way I don't know if "myapp" is a generic name )

                              You tell the linker to link against a library libmyapp.so, and -L specifies the path to this library. So check if you have such a library (and where!), and if it already exists at the time the linker is invoked.

                              By the way: /home/d07876/Desktop/Ancrage/Code interface graphique ancrage/build-anchorage-QT5-Debug/app'

                              I strongly advice against project paths containing spaces or other special characters! Already this small piece might lead to build, debug or deploy errors.

                              Regards

                              Qt has to stay free or it will die.

                              1 Reply Last reply
                              0
                              • R Offline
                                R Offline
                                R.griset
                                wrote on 27 Dec 2019, 12:50 last edited by
                                #27

                                Hello aha_1980 and thanks for your advices,

                                No I don't have "libmyapp.so" anywhere because it should be compile from src folder and call by the application from app folder. At the beggining in the code it was written "app" but it doesn't compile because it is looking for a main function which doesn't exist in src.

                                Thanks for the advice about the folder name, once again it s not my project but I changed the name ;)

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 27 Dec 2019, 13:05 last edited by
                                  #28

                                  That's the main issue here: the project as written by default can't compile because what you have in the arc folder should be built as a library and that library linked to your application.

                                  If anything, I would recommend starting by cleaning up the project structure so you have something clear to use.

                                  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
                                  • R Offline
                                    R Offline
                                    R.griset
                                    wrote on 27 Dec 2019, 13:36 last edited by
                                    #29

                                    Ok lets try :),

                                    I compiled src as lib appart and i'm having a libsrc.so in a build-src-QT5-Debug folder

                                    Now, I removed src folder from the MainPro.pro and I added the line

                                    LIBS += -L../build-src-QT5-Debug/ -lsrc in my app.pro file

                                    And i'm still getting an error :

                                    14:32:57: Starting: "/usr/bin/make"
                                    cd app/ && ( test -e Makefile || /usr/lib/x86_64-linux-gnu/qt5/bin/qmake /home/d07876/Desktop/Ancrage/UIAncrage/UI_11_05_test1Folder/app/app.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ) && /usr/bin/make -f Makefile
                                    make[1]: Entering directory '/home/d07876/Desktop/Ancrage/UIAncrage/build-anchorage-QT5-testLibAppart/app'
                                    /usr/lib/x86_64-linux-gnu/qt5/bin/qmake -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug -o Makefile ../../UI_11_05_test1Folder/app/app.pro
                                    g++ -Wl,-rpath,'$ORIGIN/../src',--enable-new-dtags -o app main.o -L/usr/X11R6/lib64 -L../build-src-QT5-Debug/ -lsrc -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread
                                    /usr/bin/ld: cannot find -lsrc

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 27 Dec 2019, 13:44 last edited by
                                      #30

                                      As already suggested use OUT_PWD to have a full path to the folder where the library can be found.

                                      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
                                      • R Offline
                                        R Offline
                                        R.griset
                                        wrote on 27 Dec 2019, 13:57 last edited by
                                        #31

                                        But if I compile src appart from app then the OUT_PWD variable doesn't lead to the right path, no ?

                                        1 Reply Last reply
                                        0
                                        • S Offline
                                          S Offline
                                          SGaist
                                          Lifetime Qt Champion
                                          wrote on 27 Dec 2019, 14:06 last edited by
                                          #32

                                          How are you building it ?

                                          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

                                          22/35

                                          26 Dec 2019, 14:02

                                          • Login

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