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. Generate a makefile without a main function from Qmake - "undefined reference to `main' "

Generate a makefile without a main function from Qmake - "undefined reference to `main' "

Scheduled Pinned Locked Moved Solved General and Desktop
qmake makefilemainprotobuf
12 Posts 4 Posters 1.1k 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.
  • N Offline
    N Offline
    NikoBir
    wrote on 8 Nov 2022, 09:46 last edited by
    #1

    Hello everyone !

    I'm currently trying to generate protobuf files with qmake.
    But when I execute the makefile, I have :

    • My correctly generated protobuf files (yes !).
    • An error : "undefined reference to `main' "

    I don't want to have a main function, I just want to generate some files. So, I don't need to have a main function .... But Qmake really want it....
    How can I explain him that it's just fine and cool ?

    I tested to change my TEMPLATE in my .pro but it changes nothing ...

    These files are in the same folder :

    My .pro :

    QT -= gui
    TEMPLATE += lib
    INCLUDEPATH += /usr/include/
    LIBS += /usr/lib/libprotobuf.so
    PROTOS = comGRPC.proto
    include(protobuf.pri)
    

    My .pri :

    PROTOPATH += .
    PROTOPATH += ../Protocol
    PROTOPATHS =
    for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
    
    protobuf_decl.name = protobuf header
    protobuf_decl.input = PROTOS
    protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
    protobuf_decl.commands = /usr/bin/protoc --cpp_out="." $${PROTOPATHS} ${QMAKE_FILE_NAME}
    protobuf_decl.variable_out = GENERATED_FILES
    QMAKE_EXTRA_COMPILERS += protobuf_decl
    
    protobuf_impl.name = protobuf implementation
    protobuf_impl.input = PROTOS
    protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc
    protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h
    protobuf_impl.commands = $$escape_expand(\n)
    protobuf_impl.variable_out = GENERATED_SOURCES
    QMAKE_EXTRA_COMPILERS += protobuf_impl
    
    J 2 Replies Last reply 8 Nov 2022, 09:56
    0
    • N NikoBir
      8 Nov 2022, 09:46

      Hello everyone !

      I'm currently trying to generate protobuf files with qmake.
      But when I execute the makefile, I have :

      • My correctly generated protobuf files (yes !).
      • An error : "undefined reference to `main' "

      I don't want to have a main function, I just want to generate some files. So, I don't need to have a main function .... But Qmake really want it....
      How can I explain him that it's just fine and cool ?

      I tested to change my TEMPLATE in my .pro but it changes nothing ...

      These files are in the same folder :

      My .pro :

      QT -= gui
      TEMPLATE += lib
      INCLUDEPATH += /usr/include/
      LIBS += /usr/lib/libprotobuf.so
      PROTOS = comGRPC.proto
      include(protobuf.pri)
      

      My .pri :

      PROTOPATH += .
      PROTOPATH += ../Protocol
      PROTOPATHS =
      for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
      
      protobuf_decl.name = protobuf header
      protobuf_decl.input = PROTOS
      protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
      protobuf_decl.commands = /usr/bin/protoc --cpp_out="." $${PROTOPATHS} ${QMAKE_FILE_NAME}
      protobuf_decl.variable_out = GENERATED_FILES
      QMAKE_EXTRA_COMPILERS += protobuf_decl
      
      protobuf_impl.name = protobuf implementation
      protobuf_impl.input = PROTOS
      protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc
      protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h
      protobuf_impl.commands = $$escape_expand(\n)
      protobuf_impl.variable_out = GENERATED_SOURCES
      QMAKE_EXTRA_COMPILERS += protobuf_impl
      
      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 8 Nov 2022, 09:56 last edited by
      #2

      @NikoBir said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

      How can I explain him that it's just fine and cool ?

      What exact pro file do you build?
      If it is My.pro then it should work as it is a library pro file.
      Also, did you change TEMPLATE to lib or was it always a lib?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NikoBir
        wrote on 8 Nov 2022, 10:15 last edited by
        #3

        Thanks for your answer, yes it's my pro file that I want to build.
        I added TEMPLATE += lib because I read that I need to use this variable if I want to build without a main function.

        J 1 Reply Last reply 8 Nov 2022, 11:47
        0
        • N NikoBir
          8 Nov 2022, 10:15

          Thanks for your answer, yes it's my pro file that I want to build.
          I added TEMPLATE += lib because I read that I need to use this variable if I want to build without a main function.

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 8 Nov 2022, 11:47 last edited by
          #4

          @NikoBir said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

          I added TEMPLATE += lib because I read that I need to use this variable if I want to build without a main function

          That is clear. My question is whether you had something else there and then changed to lib. If that's the case then delete everything in build folder, run qmake and build.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          S 1 Reply Last reply 8 Nov 2022, 20:24
          0
          • N Offline
            N Offline
            NikoBir
            wrote on 8 Nov 2022, 12:14 last edited by
            #5

            Ah ! I misunderstood ! Yes, I had nothing before. I even didn't had a TEMPLATE variable.
            Like you said I removed everything in the build folder, ran qmake and built but I have the same issue.

            1 Reply Last reply
            0
            • N NikoBir
              8 Nov 2022, 09:46

              Hello everyone !

              I'm currently trying to generate protobuf files with qmake.
              But when I execute the makefile, I have :

              • My correctly generated protobuf files (yes !).
              • An error : "undefined reference to `main' "

              I don't want to have a main function, I just want to generate some files. So, I don't need to have a main function .... But Qmake really want it....
              How can I explain him that it's just fine and cool ?

              I tested to change my TEMPLATE in my .pro but it changes nothing ...

              These files are in the same folder :

              My .pro :

              QT -= gui
              TEMPLATE += lib
              INCLUDEPATH += /usr/include/
              LIBS += /usr/lib/libprotobuf.so
              PROTOS = comGRPC.proto
              include(protobuf.pri)
              

              My .pri :

              PROTOPATH += .
              PROTOPATH += ../Protocol
              PROTOPATHS =
              for(p, PROTOPATH):PROTOPATHS += --proto_path=$${p}
              
              protobuf_decl.name = protobuf header
              protobuf_decl.input = PROTOS
              protobuf_decl.output = ${QMAKE_FILE_BASE}.pb.h
              protobuf_decl.commands = /usr/bin/protoc --cpp_out="." $${PROTOPATHS} ${QMAKE_FILE_NAME}
              protobuf_decl.variable_out = GENERATED_FILES
              QMAKE_EXTRA_COMPILERS += protobuf_decl
              
              protobuf_impl.name = protobuf implementation
              protobuf_impl.input = PROTOS
              protobuf_impl.output = ${QMAKE_FILE_BASE}.pb.cc
              protobuf_impl.depends = ${QMAKE_FILE_BASE}.pb.h
              protobuf_impl.commands = $$escape_expand(\n)
              protobuf_impl.variable_out = GENERATED_SOURCES
              QMAKE_EXTRA_COMPILERS += protobuf_impl
              
              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 8 Nov 2022, 12:18 last edited by
              #6

              @NikoBir said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

              LIBS += /usr/lib/libprotobuf.so

              This line is wrong please seee here how to do it properly: https://doc.qt.io/qt-6/qmake-variable-reference.html#libs), but not the cause for your issue I think.
              Can you provide a minimal reproducible project, so others can try?

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NikoBir
                wrote on 8 Nov 2022, 13:11 last edited by
                #7

                Thank you, yes I can !
                I created this repository with my zipped project. I added the includes and libs.

                https://github.com/QtForumHelp/undefined_reference_to_main_Qmake-Protobuf

                J 1 Reply Last reply 8 Nov 2022, 13:20
                0
                • N NikoBir
                  8 Nov 2022, 13:11

                  Thank you, yes I can !
                  I created this repository with my zipped project. I added the includes and libs.

                  https://github.com/QtForumHelp/undefined_reference_to_main_Qmake-Protobuf

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 8 Nov 2022, 13:20 last edited by
                  #8

                  @NikoBir I will check (it does not build for me). But your LIBS is still wrong...

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    NikoBir
                    wrote on 8 Nov 2022, 13:38 last edited by
                    #9

                    Ok I will correct it !

                    1 Reply Last reply
                    0
                    • J jsulm
                      8 Nov 2022, 11:47

                      @NikoBir said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

                      I added TEMPLATE += lib because I read that I need to use this variable if I want to build without a main function

                      That is clear. My question is whether you had something else there and then changed to lib. If that's the case then delete everything in build folder, run qmake and build.

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 8 Nov 2022, 20:24 last edited by SGaist 11 Oct 2022, 19:29
                      #10

                      Hi,

                      @jsulm said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

                      @NikoBir said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

                      I added TEMPLATE += lib because I read that I need to use this variable if I want to build without a main function

                      That is clear. My question is whether you had something else there and then changed to lib. If that's the case then delete everything in build folder, run qmake and build.

                      In addition to what @jsulm, TEMPLATE should contain a single value. Here you likely have something else. So just in case, replace it with TEMPLATE = lib.

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

                      Paul ColbyP 1 Reply Last reply 10 Nov 2022, 09:58
                      3
                      • S SGaist
                        8 Nov 2022, 20:24

                        Hi,

                        @jsulm said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

                        @NikoBir said in Generate a makefile without a main function from Qmake - "undefined reference to `main' ":

                        I added TEMPLATE += lib because I read that I need to use this variable if I want to build without a main function

                        That is clear. My question is whether you had something else there and then changed to lib. If that's the case then delete everything in build folder, run qmake and build.

                        In addition to what @jsulm, TEMPLATE should contain a single value. Here you likely have something else. So just in case, replace it with TEMPLATE = lib.

                        Paul ColbyP Offline
                        Paul ColbyP Offline
                        Paul Colby
                        wrote on 10 Nov 2022, 09:58 last edited by
                        #11

                        @SGaist wrote:

                        TEMPLATE should contain a single value. Here you likely something else. So just in case, replace it with TEMPLATE = lib.

                        Indeed, as per the docs, TEMPLATE defaults to app. So by using += the TEMPLATE ends up being app lib, which is not what you want :)

                        So, as @SGaist indicated, drop the + from that line so:

                        TEMPLATE = lib
                        

                        Cheers.

                        1 Reply Last reply
                        2
                        • N Offline
                          N Offline
                          NikoBir
                          wrote on 10 Nov 2022, 15:01 last edited by
                          #12

                          Thank you all ! It worked !!!!!

                          Yes the solution was TEMPLATE = lib !

                          1 Reply Last reply
                          0

                          1/12

                          8 Nov 2022, 09:46

                          • Login

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