View previous topic :: View next topic |
Author |
Message |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Sun Jun 24, 2018 8:08 am Post subject: Project running without errors, but no correct result. |
|
|
Dear Mr. Bernard,
Bonjour!
I am using your .h files and lib file in my project. The .lib file I used comes from what you have compiled in Download page of this website: upnpc-exe-win32-20150918.zip, namely, "miniupnpc.lib", and the header files I used are copied from miniupnpc-2.0.20180503.tar.gz on the Download page.
But when "UPNP GetValidIGD" was executed, the returned value is always 0, instead of 1. I tried change to different WIFI(i.e. NAT device), the result remains the same.
Would you please give me some hints when you are not very busy? Your help is greatly appriciated! Thanks a lot.
header files included in my project:
igd_desc_parse.h
miniupnpc.h
miniupnpc_declspec.h
miniupnpctypes.h
miniwget.h
upnpcommands.h
upnpdev.h
upnperrors.h
Code: | #include <QCoreApplication>
#include <QDebug>
#include <winsock2.h>
extern "C"
{
#include "miniupnpc.h"
#include "miniwget.h"
#include "upnpcommands.h"
#include "upnperrors.h"
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData);
//step 1
const char * multicastif=nullptr;
const char * minissdpdpath=nullptr;
struct UPNPDev * devlist=nullptr;
int error=0;
devlist=upnpDiscover(2000,multicastif,minissdpdpath,0,0,2,&error);
//step 2
struct UPNPUrls urls;
struct IGDdatas data;
int r;
char lanaddr[64];
r=UPNP_GetValidIGD(devlist,&urls,&data,lanaddr,sizeof(lanaddr));
qDebug()<<"result: "<<r;
WSACleanup();
return a.exec();
} |
|
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Jun 25, 2018 9:32 am Post subject: Re: Project running without errors, but no correct result. |
|
|
str999cn wrote: |
I am using your .h files and lib file in my project. The .lib file I used comes from what you have compiled in Download page of this website: upnpc-exe-win32-20150918.zip, namely, "miniupnpc.lib", and the header files I used are copied from miniupnpc-2.0.20180503.tar.gz on the Download page.
[/code] |
Don't use .h and .lib from different packages.
Just use the latest sources miniupnpc-2.1.tar.gz and build the lib from it. Which compiler are you using ? _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Mon Jun 25, 2018 12:37 pm Post subject: |
|
|
ok, now I have just downloaded the newest version miniupnpc-2.1.tar.gz dated on 07/05/2018.
I am using Microsoft Visual Studio 2015, because I have seen in the folder of msvc, there is file of "miniupnpc_vs2015.sln".
Several minutes I have just compiled your solution(2 projects incluede), and there is just one .lib file as the output? There is no .dll output for the compilation, right?
Thank you for you patience to reply to me.
Tom |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Jun 25, 2018 2:43 pm Post subject: |
|
|
Yes I think the msvc project is outputing a static library _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Jun 25, 2018 2:44 pm Post subject: |
|
|
By the way, have you tested other UPnP IGD clients on your machine and network ? _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Mon Jun 25, 2018 6:24 pm Post subject: |
|
|
Hello,
I have compiled this solution "miniupnpc-2.1.tar.gz" in Microsoft Visual Studio 2015. And in the folder of "Release" under folder of "msvc" I have got one library file named "miniupnpc.lib".
After that, I included this .lib file, along with several other header files coming from the same package, in my project in VS2015. When the project was run, an error occured: LNK2019 UNRESOLVED EXTERNAL SYMBOLS '_imp__upnpDiscover'.
Then I tried again in Qt5.3, using the same library and corresponding header files. And the result is the same: undefined reference to '_imp__upnpDiscover'.
It seems that there was something wrong in my compiling of your solution(project). I will try again later.
Merci! |
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Mon Jun 25, 2018 6:26 pm Post subject: |
|
|
The following is demonstration code in VS 2015 in one computer:
Code: | #include "stdafx.h"
#include <iostream>
#include <WinSock2.h>
#include "igd_desc_parse.h"
#include "miniupnpc.h"
#include "miniupnpc_declspec.h"
#include "upnpdev.h"
using namespace std;
int main()
{
WSADATA wsaData;
WSAStartup(MAKEWORD(2, 2), &wsaData);
const char * multicastif = nullptr;
const char * minissdpdpath = nullptr;
struct UPNPDev * devlist = nullptr;
int error = 0;
devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error);
cout << "error: " << error << endl;
system("pause");
WSACleanup();
return 0;
} |
Last edited by str999cn on Mon Jun 25, 2018 6:30 pm; edited 2 times in total |
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Mon Jun 25, 2018 6:29 pm Post subject: |
|
|
The folloing code is from Qt5.3 in ANOTHER computer.(I tested in two seperated computers respectively with the same .lib and header files)
Code: | #include <QCoreApplication>
#include <winsock2.h>
#include <QDebug>
extern "C"
{
#include "miniupnpc.h"
#include "miniwget.h"
#include "upnpcommands.h"
#include "upnperrors.h"
#include "miniupnpc_declspec.h"
#include "igd_desc_parse.h"
#include "upnpdev.h"
#include "miniupnpctypes.h"
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
WSADATA wsaData;
WSAStartup(MAKEWORD(2,2),&wsaData);
//step 1
const char * multicastif=nullptr;
const char * minissdpdpath=nullptr;
struct UPNPDev * devlist=nullptr;
int error=0;
devlist=upnpDiscover(2000,multicastif,minissdpdpath,0,0,2,&error);
qDebug()<<"error: "<<error;
//step 2
struct UPNPUrls urls;
struct IGDdatas data;
int r;
char lanaddr[64];
r=UPNP_GetValidIGD(devlist,&urls,&data,lanaddr,sizeof(lanaddr));
qDebug()<<"result: "<<r;
WSACleanup();
return a.exec();
} |
|
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Mon Jun 25, 2018 8:03 pm Post subject: |
|
|
Make sure your project defines MINIUPNP_STATICLIB just as the sample msvc projects. _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Tue Jun 26, 2018 6:32 am Post subject: |
|
|
Yes, I have just tested by adding #define MINIUPNP_STATICLIB. This time, running result is different, errors still occured, but errors are new:
LNK2001 UNRESOLVED EXTERNAL SYMBOLS _GetBestRoute@12
LNK2001 UNRESOLVED EXTERNAL SYMBOLS _GetIpAddrTable@12
I have seen in the package of "upnpc-exe-win32-20150918.zip" that apart from library file of "miniupnpc.lib", there is still another dynamic linking library file named "miniupnpc.dll". But now what I have compiled out is only one .lib file. Did I miss one .dll file? |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
Posted: Fri Jul 13, 2018 4:02 pm Post subject: |
|
|
str999cn wrote: | Yes, I have just tested by adding #define MINIUPNP_STATICLIB. This time, running result is different, errors still occured, but errors are new:
LNK2001 UNRESOLVED EXTERNAL SYMBOLS _GetBestRoute@12
LNK2001 UNRESOLVED EXTERNAL SYMBOLS _GetIpAddrTable@12
I have seen in the package of "upnpc-exe-win32-20150918.zip" that apart from library file of "miniupnpc.lib", there is still another dynamic linking library file named "miniupnpc.dll". But now what I have compiled out is only one .lib file. Did I miss one .dll file? |
Why don't you follow my advice and use same parameters as the sample MSVC projects ?
Everything is there : https://github.com/miniupnp/miniupnp/blob/master/miniupnpc/msvc/upnpc-static.vcxproj#L65
The microsoft documentation for GetBestRoute and GetIpAddrTable also gives you the answer :
https://docs.microsoft.com/en-us/windows/desktop/api/iphlpapi/nf-iphlpapi-getbestroute _________________ Main miniUPnP author.
https://miniupnp.tuxfamily.org/ |
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Sat Jul 14, 2018 3:13 am Post subject: |
|
|
Dear Mr. Bernard,
I am following your advice.
I have tried, this time, opening your project by use of "upnpc-static.vcxproj". The compiler of VS2015 reminded that file of "miniupnpcstrings.h" was missing. After browsing, I found two files:
"miniupnpcstrings.h.cmake"
"miniupnpcstrings.h.in"
And I have renamed them into "miniupnpcstrings.h" respectively in different compilation.
But the same error occured: "LNK1181 unable to open file 'miniupnpc.lib'".
Why is that? Isn't this lib file is what we want to generate here? Why it said unable to open it? |
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1593
|
|
Back to top |
|
 |
str999cn
Joined: 24 Jun 2018 Posts: 8
|
Posted: Sat Jul 14, 2018 11:16 am Post subject: |
|
|
Dear Mr. Bernard,
I have compiled the lib file successfully. And now I have included the necessary .h, .lib, .dll file from Micsoroft's library.
Now it works!
Thank you very much for your instruction and your patience with me. And congratulations to you and to the French football team. I wish that France will be the champion of FIFA 2018 Russia.
Yours sincerely,
Tom |
|
Back to top |
|
 |
|