Generate a makefile without a main function from Qmake - "undefined reference to `main' "
-
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
-
@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? -
@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.
-
@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? -
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
-
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
. -
@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 toapp
. So by using+=
theTEMPLATE
ends up beingapp lib
, which is not what you want :)So, as @SGaist indicated, drop the
+
from that line so:TEMPLATE = lib
Cheers.