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 

Compilation error on Windows

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



Joined: 10 May 2010
Posts: 5

PostPosted: Mon May 10, 2010 9:15 pm    Post subject: Compilation error on Windows Reply with quote

Running Windows 7 with MingW installed.

From the command prompt I first add:
path = %PATH%;C:\mingw\bin

Then I run mingw32make.bat from the Windows command prompt.

This is the result:
gcc wingenminiupnpcstrings.o -lws2_32 -liphlpapi -o wingenminiupnpcstrings
wingenminiupnpcstrings miniupnpcstrings.h.in miniupnpcstrings.h
Windows 6.1 Build 7600
15 lines written to miniupnpcstrings.h.
gcc -Wall -Os -DNDEBUG -DSTATICLIB -c -o miniwget.o miniwget.c
miniwget.c: In function `miniwget3':
miniwget.c:87: warning: implicit declaration of function `getnameinfo'
gcc -Wall -Os -DNDEBUG -DMINIUPNP_EXPORTS -c -o dll/miniwget.o miniwget.c
miniwget.c: In function `miniwget3':
miniwget.c:87: warning: implicit declaration of function `getnameinfo'
gcc -Wall -Os -DNDEBUG -DSTATICLIB -c -o minixml.o minixml.c
gcc -Wall -Os -DNDEBUG -DMINIUPNP_EXPORTS -c -o dll/minixml.o minixml.c
ar cr libminiupnpc.a miniwget.o minixml.o
gcc -o upnpc-static upnpc.o libminiupnpc.a -lws2_32 -liphlpapi
libminiupnpc.a(miniupnpc.o):miniupnpc.cSad.text+0x627): undefined reference to `g
etaddrinfo'
libminiupnpc.a(miniupnpc.o):miniupnpc.cSad.text+0x68e): undefined reference to `f
reeaddrinfo'
libminiupnpc.a(miniwget.o):miniwget.cSad.text+0xaa): undefined reference to `getn
ameinfo'
libminiupnpc.a(connecthostport.o):connecthostport.cSad.text+0x46): undefined refe
rence to `getaddrinfo'
libminiupnpc.a(connecthostport.o):connecthostport.cSad.text+0xa8): undefined refe
rence to `freeaddrinfo'
collect2: ld returned 1 exit status
mingw32-make: *** [upnpc-static] Error 1

Any advice on what I'm doing wrong?
Back to top
View user's profile Send private message
joereed



Joined: 10 May 2010
Posts: 5

PostPosted: Tue May 11, 2010 4:28 am    Post subject: Reply with quote

Based on what I found online I tried adding this to the top of files that threw errors:
#define _WIN32_WINNT 0x0501

This appeared to compile okay, but when I statically compiled the result into my program and actually tried to use it, it would seg fault on calling UPNP_GetValidIGD.

This doesn't occur when I use the precompiled DLLs.

Any help on how I can compile miniupnpc myself on Windows so that I can statically link it into my program?
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Tue May 11, 2010 2:00 pm    Post subject: Reply with quote

I need to test again with MinGW. It worked with MS Visual C 2008 express.
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
joereed



Joined: 10 May 2010
Posts: 5

PostPosted: Tue May 11, 2010 2:41 pm    Post subject: Reply with quote

Great thanks for the responsiveness!

Maybe in the future would it be possible for you to include a static compiled version in the pre-compiled bundle?
Back to top
View user's profile Send private message
joereed



Joined: 10 May 2010
Posts: 5

PostPosted: Wed May 12, 2010 3:15 pm    Post subject: Reply with quote

FYI, in case this is any help, the 0202 build compiles fine here, but the next 0405 build fails with errors.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Thu May 13, 2010 4:55 pm    Post subject: Reply with quote

I have no problem to compile on my Vista Pro (32bits) Machine (6.0.6002) with mingw (gcc 3.4.2).

I added the .a file to upnpc-exe-win32-20100513.zip
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
joereed



Joined: 10 May 2010
Posts: 5

PostPosted: Thu May 13, 2010 5:09 pm    Post subject: Reply with quote

Thanks, I'm just as happy if I don't have to compile and the releases contain the .a file.

Wonder if this is related to the fact that I'm running Win7 x64.
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Fri May 14, 2010 2:24 pm    Post subject: Reply with quote

joereed wrote:
Thanks, I'm just as happy if I don't have to compile and the releases contain the .a file.

Wonder if this is related to the fact that I'm running Win7 x64.

I dont know. Is your mingw32 a 64 bit version ???
I dont know how to check the version of an installed mingw32. Maybe the version you are using is causing troubles.
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
ronybeck



Joined: 27 Jun 2010
Posts: 3

PostPosted: Sun Jun 27, 2010 12:16 pm    Post subject: Reply with quote

miniupnp wrote:
joereed wrote:
Thanks, I'm just as happy if I don't have to compile and the releases contain the .a file.

Wonder if this is related to the fact that I'm running Win7 x64.

I dont know. Is your mingw32 a 64 bit version ???
I dont know how to check the version of an installed mingw32. Maybe the version you are using is causing troubles.


I had the same thing with Windows 7 both 64bit and 32bit. I am using TDM 4.5 32bit iteration of mingw. For me I found adding the following lines to miniupnpc.c and miniwget.c allowed me to compile fine.

Code:
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
void WSAAPI freeaddrinfo (struct addrinfo*);
int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,struct addrinfo**);
int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,char*,DWORD,int);
#endif



How ever I can't link the libraries to my own projects. Here is the output I get:

    mingw32-gcc -c -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi testupnp.cpp -o testupnp.o
    mingw32-gcc -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi ./deps/lib/miniupnp/libminiupnpc.a testupnp.o
    -o testupnp.exe
    testupnp.o: In function `SetRedirectAndTest':
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:63: undefined reference to `_imp__UPNP_GetExternalIPAddress'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:70: undefined reference to `_imp__UPNP_AddPortMapping'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:73: undefined reference to `_imp__strupnperror'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:78: undefined reference to `_imp__UPNP_GetSpecificPortMappingEntry'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:81: undefined reference to `_imp__strupnperror'
    testupnp.o: In function `main':
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:91: undefined reference to `__gxx_personality_sj0'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:112: undefined reference to `WSAStartup@8'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:120: undefined reference to `_imp__upnpDiscover'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:131: undefined reference to `_imp__UPNP_GetValidIGD'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:135: undefined reference to `__cxa_begin_catch'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:135: undefined reference to `__cxa_end_catch'
    collect2: ld returned 1 exit status
    make: *** [all] Error 1


The symbols the linker is looking for don't seem right but I don't enough about symbols and linking to nut that out. Any one know the answer here?
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Sun Jun 27, 2010 6:35 pm    Post subject: Reply with quote

ronybeck wrote:

[...]
How ever I can't link the libraries to my own projects. Here is the output I get:

    mingw32-gcc -c -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi testupnp.cpp -o testupnp.o
    mingw32-gcc -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi ./deps/lib/miniupnp/libminiupnpc.a testupnp.o
    -o testupnp.exe
    testupnp.o: In function `SetRedirectAndTest':
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:63: undefined reference to `_imp__UPNP_GetExternalIPAddress'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:70: undefined reference to `_imp__UPNP_AddPortMapping'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:73: undefined reference to `_imp__strupnperror'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:78: undefined reference to `_imp__UPNP_GetSpecificPortMappingEntry'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:81: undefined reference to `_imp__strupnperror'
    testupnp.o: In function `main':
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:91: undefined reference to `__gxx_personality_sj0'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:112: undefined reference to `WSAStartup@8'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:120: undefined reference to `_imp__upnpDiscover'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:131: undefined reference to `_imp__UPNP_GetValidIGD'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:135: undefined reference to `__cxa_begin_catch'
    C:\Users\Ronnie Beck\workspace\testupnp/testupnp.cpp:135: undefined reference to `__cxa_end_catch'
    collect2: ld returned 1 exit status
    make: *** [all] Error 1


The symbols the linker is looking for don't seem right but I don't enough about symbols and linking to nut that out. Any one know the answer here?

In order to compile your C++ code you should call mingw-g++ not gcc.
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
ronybeck



Joined: 27 Jun 2010
Posts: 3

PostPosted: Mon Jun 28, 2010 9:24 am    Post subject: Reply with quote

ronybeck wrote:

In order to compile your C++ code you should call mingw-g++ not gcc.


Sorry, the file name is deceptive. The code is C only which is why it compiles with a C compiler. Only the linking fails. For the record, the same code compiles fine as a C programme on linux. Are there some flags I need to supply to link against miniupnp under mingw32.

Code:

mingw32-gcc -c -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi testupnp.c -o testupnp.o
mingw32-gcc -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi ./deps/lib/miniupnp/libminiupnpc.a testupnp.o
 -o testupnp.exe
testupnp.o: In function `SetRedirectAndTest':
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:60: undefined reference to `_imp__UPNP_GetExternalIPAddress'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:68: undefined reference to `_imp__UPNP_AddPortMapping'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:71: undefined reference to `_imp__strupnperror'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:74: undefined reference to `_imp__UPNP_GetSpecificPortMappingEntry'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:79: undefined reference to `_imp__strupnperror'
testupnp.o: In function `main':
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:109: undefined reference to `WSAStartup@8'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:117: undefined reference to `_imp__upnpDiscover'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:128: undefined reference to `_imp__UPNP_GetValidIGD'
collect2: ld returned 1 exit status
make: *** [all] Error 1


If I run strings on the library files I see the symbols take a different naming convention:

e.g.
Code:
_UPNP_GetSpecificPortMappingEntry
_UPNP_GetPortMappingNumberOfEntries
_UPNP_GetGenericPortMappingEntry
_UPNP_DeletePortMapping
_UPNP_AddPortMapping
_UPNP_GetExternalIPAddress
_UPNP_GetLinkLayerMaxBitRates
_UPNP_GetConnectionTypeInfo
_UPNP_GetStatusInfo
_UPNP_GetTotalPacketsReceived
_UPNP_GetTotalPacketsSent
_UPNP_GetTotalBytesReceived
_UPNP_GetTotalBytesSent
_strupnperror
_connecthostport
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1454

PostPosted: Mon Jun 28, 2010 2:00 pm    Post subject: Reply with quote

ronybeck wrote:
ronybeck wrote:

In order to compile your C++ code you should call mingw-g++ not gcc.


Sorry, the file name is deceptive. The code is C only which is why it compiles with a C compiler. Only the linking fails. For the record, the same code compiles fine as a C programme on linux. Are there some flags I need to supply to link against miniupnp under mingw32.

When the extension is cpp, the code needs some C++ runtime stuff, like `__cxa_begin_catch' and so on...

ronybeck wrote:

Code:

mingw32-gcc -c -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi testupnp.c -o testupnp.o
mingw32-gcc -g -I./deps/include/miniupnp/ -L./deps/lib/miniupnp/ -lws2_32 -lwsock32 -liphlpapi ./deps/lib/miniupnp/libminiupnpc.a testupnp.o
 -o testupnp.exe
testupnp.o: In function `SetRedirectAndTest':
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:60: undefined reference to `_imp__UPNP_GetExternalIPAddress'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:68: undefined reference to `_imp__UPNP_AddPortMapping'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:71: undefined reference to `_imp__strupnperror'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:74: undefined reference to `_imp__UPNP_GetSpecificPortMappingEntry'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:79: undefined reference to `_imp__strupnperror'
testupnp.o: In function `main':
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:109: undefined reference to `WSAStartup@8'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:117: undefined reference to `_imp__upnpDiscover'
C:\Users\Ronnie Beck\workspace\testupnp/testupnp.c:128: undefined reference to `_imp__UPNP_GetValidIGD'
collect2: ld returned 1 exit status
make: *** [all] Error 1


If I run strings on the library files I see the symbols take a different naming convention:

e.g.
Code:
_UPNP_GetSpecificPortMappingEntry
_UPNP_GetPortMappingNumberOfEntries
_UPNP_GetGenericPortMappingEntry
_UPNP_DeletePortMapping
_UPNP_AddPortMapping
_UPNP_GetExternalIPAddress
_UPNP_GetLinkLayerMaxBitRates
_UPNP_GetConnectionTypeInfo
_UPNP_GetStatusInfo
_UPNP_GetTotalPacketsReceived
_UPNP_GetTotalPacketsSent
_UPNP_GetTotalBytesReceived
_UPNP_GetTotalBytesSent
_strupnperror
_connecthostport

I believe it is caused by the missing STATICLIB define.
Make sure it is defined
_________________
Main miniUPnP author.
http://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
ronybeck



Joined: 27 Jun 2010
Posts: 3

PostPosted: Sun Jul 04, 2010 10:14 am    Post subject: Reply with quote

Thanks for the tip. That helped me a lot how ever I also needed to change the linking order.

Code:
C:\Users\Ronnie Beck\workspace\testupnp>make
mingw32-gcc -g -I./deps/include/miniupnp/ -Wall -Os -DNDEBUG -DSTATICLIB -c -o testupnp.o testupnp.c
mingw32-gcc -o testupnp.exe testupnp.o libminiupnpc.a -lws2_32 -lwsock32 -liphlpapi
Warning: resolving _getaddrinfo by linking to _getaddrinfo@16
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Warning: resolving _freeaddrinfo by linking to _freeaddrinfo@4

C:\Users\Ronnie Beck\workspace\testupnp>


So the linking order needs to be, my object first and then libminiupnpc.a.

And now it works just fine. Thank you very much for your help.
Back to top
View user's profile Send private message
alucard3186



Joined: 05 Jun 2010
Posts: 8

PostPosted: Wed Jul 28, 2010 2:42 am    Post subject: Reply with quote

i am compiling under gcc livred withe QT4.6 under win7 32 bit
the problem is that the compilation is done whitout any error but whene i run the programe "programe.exe" the system say "programe.exe is note a valide win32 programe".
so i decide to compile my programme in static mode and i rename all file *.c in *.cpp and in ws2tcpip.h i make this change:
#if (_WIN32_WINNT >= 0x0501)
void WSAAPI freeaddrinfo (struct addrinfo*);
int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
struct addrinfo**);
int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
char*,DWORD,int);
#else
/* FIXME: Need WS protocol-independent API helpers. */
void WSAAPI freeaddrinfo (struct addrinfo*);
int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,
struct addrinfo**);
int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,
char*,DWORD,int);
#endif

and in connecthostport.cpp miniwget.cpp miniupnpc.cpp i add this line:
#if (_WIN32_WINNT >= _WIN32_WINNT_WIN7)
void WSAAPI freeaddrinfo (struct addrinfo*);
int WSAAPI getaddrinfo (const char*,const char*,const struct addrinfo*,struct addrinfo**);
int WSAAPI getnameinfo(const struct sockaddr*,socklen_t,char*,DWORD,char*,DWORD,int);

#endif

and i am resoling all cast error like void * to char* .... there is many

and the compilation is donne perfectly and the execution of programe is running perfectly.



good programing
_________________
I WILL WORK
Back to top
View user's profile Send private message Send e-mail
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.