Include file not working. Getting "undefined reference to "
-
wrote on 15 Feb 2018, 00:39 last edited by
I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.
If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp. Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work. It seems to me that Qt sees the function but somehow it doesnt compile.
Any suggestions? Thank you
-
I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.
If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp. Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work. It seems to me that Qt sees the function but somehow it doesnt compile.
Any suggestions? Thank you
wrote on 15 Feb 2018, 02:48 last edited byHi @Count-Vlad,
An "undefined reference" error does not suggest a problem with the compiler finding the header (which declares the function), but more likely a problem with the compiler (or linker) not seeing the
*.cpp
file or object file containing the definition for the function.If the function is defined in your local project somewhere, make sure its
*.cpp
files is included in the*.pro
file.If the function comes from some external library, make sure the library is included in the
*.pro
file.Cheers.
-
I'm trying to create a GUI and i'm having issues with some header files that the program needs and uses.
If i click on the function in the main.cpp it takes me to the header file. But for some reason when i compile the program I get "undefined reference to " the function in main.cpp. Ive tried to add the path of the include folder where the header file in the .pro file but it didnt work. It seems to me that Qt sees the function but somehow it doesnt compile.
Any suggestions? Thank you
@Count-Vlad What header file is it? One of the Qt header files?
-
wrote on 15 Feb 2018, 05:32 last edited by yuvaram
HI @Count-Vlad
you have mentioned that, *.h header file is added, but you have not specified *.cpp file or related library is included.
Try to add *.cpp file in *.pro file. If same issue, delete build folder and re build the project. -
wrote on 15 Feb 2018, 23:23 last edited by
for some reason the compiler did not see the library that the header file needed. it was specified in the makefile but it didnt work.
in the .pro file i added
LIBS += -lmylib
and that fixed the issue. Thank you for your help
-
for some reason the compiler did not see the library that the header file needed. it was specified in the makefile but it didnt work.
in the .pro file i added
LIBS += -lmylib
and that fixed the issue. Thank you for your help
@Count-Vlad: Glad you figured it out.
LIBS += -lmylib
is indeed the correct way to tell the linker to link to your lib. If you modify the Makefiles created by Qmake, your changes will be overwritten the next timeqmake
is run.So please mark this thread as solved now.
1/6