miniupnp.tuxfamily.org Forum Index miniupnp.tuxfamily.org
The forum about miniupnp and libnatpmp
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

problem about setting-up-miniupnpc-with-qt

 
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation
View previous topic :: View next topic  
Author Message
jason001



Joined: 18 Jul 2018
Posts: 16
Location: China

PostPosted: Fri Jul 27, 2018 2:57 am    Post subject: problem about setting-up-miniupnpc-with-qt Reply with quote

Dear Mr. Bernard,

Bonjour!

I am trying to set up miniupnpc with qt, following http://mayaposch.wordpress.com/2011/09/18/setting-up-miniupnpc-with-qt/, as you mentioned in a previous topic.
I am using Qt5.8.0 (qt-opensource-windows-x86-mingw530-5.8.0), in win7 x64.
I have downloaded miniupnpc-1.9.20150917.tar.gz and upnpc-exe-win32-20150918.zip,and extracted them to C:\miniupnpctest\miniupnpc-1.9.20150917 and C:\miniupnpctest\upnpc-exe-win32-20150918.

I put the below in the qt main.cpp,
Code:

#include <miniupnpc.h>

Code:

const char * multicastif = 0;
const char * minissdpdpath = 0;
struct UPNPDev * devlist = 0;
unsigned char ttl = 0;
int error = 0;
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, ttl, &error);


In the qt *.pro,
Code:

INCLUDEPATH += C:\miniupnpctest\miniupnpc-1.9.20150917
LIBS += C:\miniupnpctest\upnpc-exe-win32-20150918\libminiupnpc.a
LIBS += -liphlpapi


and result in error:
Code:

error: undefined reference to `_imp__upnpDiscover'


It seems that the link to *.a was wrong.
How could I fix this problem?

(I also took a try to copy libminiupnpc.a to C:\Qt\Qt5.8.0\5.8\mingw53_32\lib or C:\Qt\Qt5.8.0\Tools\mingw530_32\lib, and change *.pro to be LIBS += -lminiupnpc, but it result in the same error.)

Thank you!
Yours sincerely,
Jason
Back to top
View user's profile Send private message
jason001



Joined: 18 Jul 2018
Posts: 16
Location: China

PostPosted: Fri Jul 27, 2018 7:18 am    Post subject: more Reply with quote

I have set up qt creator 2.1.0, qt 4.7.4 in C:\Qt, in winxp, and set ENV. PATH to be C:\Qt\qtcreator-2.1.0\mingw\bin. and make all above work well.
I have compiled miniupnpc-1.6 succesfully in c:\miniupnpc-1.6, by using mingw32make.bat, with the mingw mentioned above.

I put the code in the qt main.cpp
Code:

#include "dialog.h"
#include <QApplication>

#include <QDebug>

#include <miniupnpc.h>


int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Dialog w;
    w.show();

    const char * multicastif = 0;
    const char * minissdpdpath = 0;
    struct UPNPDev * devlist = 0;
    int error = 0;
    devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);

    if (devlist)
    {
        qDebug() << "devlist true!" << endl;

        struct UPNPDev * dev;
        dev = devlist;
        while (dev)
        {
            if (strstr (dev->st, "InternetGatewayDevice"))
                break;
            dev = dev->pNext;
        }
        if (!dev)
            dev = devlist; /* defaulting to first device */

        qDebug("UPnP device :\n"
               " desc: %s\n st: %s\n",
               dev->descURL, dev->st);

    }
    else
    {
        qDebug() << "devlist false!" << endl;
    }

    return a.exec();
}


In the test1.pro:
Code:

QT       += core gui

TARGET = test1
TEMPLATE = app

INCLUDEPATH += C:\miniupnpc-1.6\
LIBS += C:\miniupnpc-1.6\libminiupnpc.a
LIBS += -liphlpapi


SOURCES += main.cpp\
        dialog.cpp

HEADERS  += dialog.h


But it still result in:
Code:

error:undefined reference to `_imp__upnpDiscover'


and I copied "libminiupnpc.a" to C:\Qt\qtcreator-2.1.0\mingw\lib, and change the *.pro to be
Code:

INCLUDEPATH += C:\miniupnpc-1.6\
LIBS += -lminiupnpc
LIBS += -liphlpapi


and result in the same error.

This is quite strange, could anyone help me?

Thank you very much!
Back to top
View user's profile Send private message
jason001



Joined: 18 Jul 2018
Posts: 16
Location: China

PostPosted: Tue Jul 31, 2018 6:45 am    Post subject: success Reply with quote

work well in winxp, win7 and linux, with different version of qt.
just code:
Code:

DEFINES += STATICLIB
INCLUDEPATH += F:\vmshare\miniupnpc-1.6-success
LIBS += F:\vmshare\miniupnpc-1.6-success\libminiupnpc.a
LIBS += -liphlpapi
LIBS += -lws2_32
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1448

PostPosted: Fri Aug 03, 2018 12:46 am    Post subject: Reply with quote

just define MINIUPNP_STATICLIB if you link against the static library
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1448

PostPosted: Fri Aug 03, 2018 12:50 am    Post subject: Reply with quote

also please use the latest sources from https://miniupnp.tuxfamily.org/files/
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
jason001



Joined: 18 Jul 2018
Posts: 16
Location: China

PostPosted: Sat Aug 04, 2018 10:40 am    Post subject: Thanks for reply! Reply with quote

Thanks for your replies!
Have a good weekend!SmileSmile
Back to top
View user's profile Send private message
jason001



Joined: 18 Jul 2018
Posts: 16
Location: China

PostPosted: Tue Aug 07, 2018 3:33 am    Post subject: Reply with quote

DEFINES += STATICLIB help my simple test qt project compiled successfully and work well, but it didn't work with my complicated qt project, meeting problems like "miniupnpc.c:-1: error: undefined reference to `in6addr_any'.
Thanks to your replies, I took a try to define MINIUPNP_STATICLIB, and It works very well.
I don't know why it work well, hope I can find it out someday.
Thank you again!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    miniupnp.tuxfamily.org Forum Index -> miniupnpc Compilation/Installation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP
© 2007 Thomas Bernard, author of MiniUPNP.