adding dependencies to QT Project
-
I have created an QT Widget Project, later i added extra cpp files and corresponding headers to this QT Project. Since I added extra source files and headers to this project, I also updated my .pro file with the following three additional lines
LIBS += -lwsock32 LIBS += -lws2_32 LIBS += -lkernel32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32
I have added this because previously with added cpp files and header i built visual project so i copied all this from visual project.
But while building the QT Project i am getting errors.
The following error is being shown by qt for one of the cpp file which i addederror: 'inet_pton' was not declared in this scope if (inet_pton(AF_UNSPEC, name, &ip) == 1) ^
As per my understanding inet_pton comes from WS2tcpip.h and AF_UNSPEC comes from ws2def.h.
The below dependencies are found from visual studio project
wsock32.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
I am new to QT and also this is my first project in QT. I added this LIBS based on some of the forum previous questions but I am not sure where I am doing wrong?
-
You have to include the correct header where the function is defined. Has nothing to do with linking later on.
-
@Christian-Ehrlicher Hi Christian. Thanks for your suggestion. To be clear you mean that i need to include those specific headers using INCLUDE in .Pro file?
-
Since when do you add include files to the INCLUDE path?
-
@Christian-Ehrlicher Sorry for not getting you.
This is my .pro fileQT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Something TEMPLATE = app # The following define makes your compiler emit warnings if you use # any feature of Qt which has been marked as deprecated (the exact warnings # depend on your compiler). Please consult the documentation of the # deprecated API in order to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if you use deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 INCLUDEPATH += C:\TestRepos\Rep_Test\libs\eigen\include\eigen3\Eigen LIBS += -lwsock32 LIBS += -lws2_32 LIBS += -lkernel32 -lkernel32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32 SOURCES += \ main.cpp \ widget.cpp \ source1.cpp \ source2.cpp \ source3.cpp \ source4.cpp HEADERS += \ widget.h \ head1.h \ head2.h \ head3.hpp \ head4.hpp \ head5.hpp FORMS += \ widget.ui RESOURCES += \ resource.qrc
I am not getting what you are saying. Sorry for being dumb :-(
-
@JonB . I think i already added necessary include statement in source file where i am having Problems. I am not sure if you are saying this :-). But I will also go through code and needed documentaion once. Thanks for giving some insights will do some homework on it then comeback again and will update solution if i found one.
#include "head2.h" #include <cstdlib> #include <cstdio> #include <cstring> #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) #define OS_WIN #else #define OS_UNIX #endif #ifdef OS_UNIX #include <unistd.h> #include <netdb.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <arpa/inet.h> #endif #ifdef OS_WIN #include <ws2tcpip.h> #include <winsock2.h> #include <windows.h> #endif
-
@sm2770s
Either your reference toinet_pton
lies in some file other than the one you show, or you should read e.g. https://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found and compare the answers there to your exact situation (e.g. check yourWINVER
). Actually, I believe the accepted solution there might be saying you need#include <arpa/inet.h>
, even though you are Windows not Linux, but have a read and see what you think. -
@JonB said in adding dependencies to QT Project:
Either your reference to inet_pton lies in some file other than the one you show, or you should read e.g. https://stackoverflow.com/questions/15660203/inet-pton-identifier-not-found and compare the answers there to your exact situation (e.g. check your WINVER). Actually, I believe the accepted solution there might be saying you need #include <arpa/inet.h>, even though you are Windows not Linux, but have a read and see what you think.
Hi Jon! I am not sure but it was built successfully when i restarted my system. I am clueless what happened but it worked when i restarted. Even I tried to reproduce the error but till now not successful in reproducing error again.
-
@sm2770s
Well this really isn't an error message which should appear/disappear on system restart!Anyway, yes, mark topic as solved (either from Topic Tools at bottom, or mark your own reply post above as the "solution"). You can always re-open it if it occurs again soon.