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 

Linker errors when compiling for python, on Win7 with VS2010

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



Joined: 24 Oct 2015
Posts: 5

PostPosted: Sat Oct 24, 2015 3:33 am    Post subject: Linker errors when compiling for python, on Win7 with VS2010 Reply with quote

I am trying to compile a x64 python 3.4 extension.

I have been running into numerous issues along the way (first needing to grab Visual Studio, as Mingw only compiles 32-bit, etc). I (finally) got the source to compile, but when I go to run
Code:
python setup.py install
, there are tons of unresolved dependencies.

I had to modify the setup file so it referenced a *.lib file instead of a *.a file. Below is the new setup file:
Code:
from distutils.core import setup, Extension
from distutils import sysconfig
sysconfig.get_config_vars()["OPT"] = ''
sysconfig.get_config_vars()["CFLAGS"] = ''
setup(name="miniupnpc",
      version=open('VERSION').read().strip(),
      author='Thomas BERNARD',
      author_email='miniupnp@free.fr',
      license=open('LICENSE').read(),
      url='http://miniupnp.free.fr/',
      description='miniUPnP client',
      ext_modules=[
         Extension(name="miniupnpc", sources=["miniupnpcmodule.c"],
                   libraries=["ws2_32", "iphlpapi"],
                   extra_objects=[r"msvc\Release\upnpc-static.lib"])
      ])



My output from distutils:
Code:
C:\miniupnpc-1.9.20151008>python setupvs.py install
running install
running build
running build_ext
building 'miniupnpc' extension
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\cl.exe /c /nolo
go /Ox /MD /W3 /GS- /DNDEBUG -IC:\Python34\include -IC:\Python34\include /Tcmini
upnpcmodule.c /Fobuild\temp.win-amd64-3.4\Release\miniupnpcmodule.obj
miniupnpcmodule.c
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\Bin\amd64\link.exe /DLL /
nologo /INCREMENTAL:NO /LIBPATH:C:\Python34\libs /LIBPATH:C:\Python34\PCbuild\am
d64 ws2_32.lib iphlpapi.lib /EXPORT:PyInit_miniupnpc build\temp.win-amd64-3.4\Re
lease\miniupnpcmodule.obj msvc\Release\upnpc-static.lib /OUT:build\lib.win-amd64
-3.4\miniupnpc.pyd /IMPLIB:build\temp.win-amd64-3.4\Release\miniupnpc.lib /MANIF
ESTFILE:build\temp.win-amd64-3.4\Release\miniupnpc.pyd.manifest
miniupnpcmodule.obj : warning LNK4197: export 'PyInit_miniupnpc' specified multi
ple times; using first specification
   Creating library build\temp.win-amd64-3.4\Release\miniupnpc.lib and object bu
ild\temp.win-amd64-3.4\Release\miniupnpc.exp
miniupnpcmodule.obj : error LNK2019: unresolved external symbol FreeUPNPUrls ref
erenced in function UPnPObject_dealloc
miniupnpcmodule.obj : error LNK2019: unresolved external symbol freeUPNPDevlist
referenced in function UPnPObject_dealloc
miniupnpcmodule.obj : error LNK2019: unresolved external symbol upnpDiscover ref
erenced in function UPnP_discover
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetValidIGD
 referenced in function UPnP_selectigd
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetTotalByt
esSent referenced in function UPnP_totalbytesent
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetTotalByt
esReceived referenced in function UPnP_totalbytereceived
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetTotalPac
ketsSent referenced in function UPnP_totalpacketsent
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetTotalPac
ketsReceived referenced in function UPnP_totalpacketreceived
miniupnpcmodule.obj : error LNK2019: unresolved external symbol strupnperror ref
erenced in function UPnP_statusinfo
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetStatusIn
fo referenced in function UPnP_statusinfo
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetConnecti
onTypeInfo referenced in function UPnP_connectiontype
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetExternal
IPAddress referenced in function UPnP_externalipaddress
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_AddPortMapp
ing referenced in function UPnP_addportmapping
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_AddAnyPortM
apping referenced in function UPnP_addanyportmapping
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_DeletePortM
apping referenced in function UPnP_deleteportmapping
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_DeletePortM
appingRange referenced in function UPnP_deleteportmappingrange
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetPortMapp
ingNumberOfEntries referenced in function UPnP_getportmappingnumberofentries
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetSpecific
PortMappingEntry referenced in function UPnP_getspecificportmapping
miniupnpcmodule.obj : error LNK2019: unresolved external symbol UPNP_GetGenericP
ortMappingEntry referenced in function UPnP_getgenericportmapping
build\lib.win-amd64-3.4\miniupnpc.pyd : fatal error LNK1120: 19 unresolved exter
nals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\VC\\Bin\\
amd64\\link.exe' failed with exit status 1120


Does anyone have any clue why the dependencies are unresolved? I wish this had more windows support, as this really looks to be a great library!

-Stat
Back to top
View user's profile Send private message
statrill



Joined: 24 Oct 2015
Posts: 5

PostPosted: Sat Oct 24, 2015 3:53 am    Post subject: Reply with quote

From looking around, it looks like the .lib and .obj files were already in the /build/temp..../Release directory, but using these in the setup.py file gives the same 19 unresolved externals as well.

-Stat
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Sun Oct 25, 2015 4:17 pm    Post subject: Reply with quote

If your code is using the static lib, make sure MINIUPNP_STATICLIB is defined :

sysconfig.get_config_vars()["CFLAGS"] = '-DMINIUPNP_STATICLIB'

I'm not using Windows myself, so I havent tested, but you should make sure that is OK.
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
statrill



Joined: 24 Oct 2015
Posts: 5

PostPosted: Sun Oct 25, 2015 7:06 pm    Post subject: Reply with quote

miniupnp wrote:
If your code is using the static lib, make sure MINIUPNP_STATICLIB is defined :

sysconfig.get_config_vars()["CFLAGS"] = '-DMINIUPNP_STATICLIB'

I'm not using Windows myself, so I havent tested, but you should make sure that is OK.
Thanks much for a reply sir!

What do you mean when you say defined? Does MINIUPNP_STATICLIB have to be defined as a environment variable, or if you mean in code, where would it be defined? In the c++ portion, or in the python setup.py file? I don't even know how to check if it is defined Sad

I am not very good with c++, so please forgive me.
-Stat
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Sun Oct 25, 2015 7:52 pm    Post subject: Reply with quote

I mean through CFLAGS :
sysconfig.get_config_vars()["CFLAGS"] = '-DMINIUPNP_STATICLIB'

in MSVC project files there is PreprocessorDefinitions :
https://github.com/miniupnp/miniupnp/blob/master/miniupnpc/msvc/upnpc-static.vcproj#L44
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
statrill



Joined: 24 Oct 2015
Posts: 5

PostPosted: Sun Oct 25, 2015 9:31 pm    Post subject: Reply with quote

Ahh, okay. If I open them up with VS2010, upnpc-static has all of the definitions in the link you posted. The miniupnpc project has only _CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB;%(PreprocessorDefinitions).

But yes, they both have MINIUPNP_STATICLIB defined. Both projects compile in VS2010 - but when I use the setup.py, everything falls apart :/

-Stat
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Sun Oct 25, 2015 10:44 pm    Post subject: Reply with quote

that's why I gave you the line to change in setup.py ...
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
statrill



Joined: 24 Oct 2015
Posts: 5

PostPosted: Mon Oct 26, 2015 6:31 am    Post subject: Reply with quote

I just realized the misunderstanding - I was trying to compile in VS2010 and have python somehow build the extension from that; I just did some more reading and learned that the python build process compiles from scratch.

Anyway, I'm with you now. I defined the CFLAG, but I still get the 19 LNK2019s. My file now looks like this:

Code:
from distutils.core import setup, Extension
from distutils import sysconfig
sysconfig.get_config_vars()["OPT"] = ''
sysconfig.get_config_vars()["CFLAGS"]= '-DMINIUPNP_STATICLIB'
setup(name="miniupnpc",
      version=open('VERSION').read().strip(),
      author='Thomas BERNARD',
      author_email='miniupnp@free.fr',
      license=open('LICENSE').read(),
      url='http://miniupnp.free.fr/',
      description='miniUPnP client',
      ext_modules=[
         Extension(name="miniupnpc", sources=["miniupnpcmodule.c"],
                   libraries=["ws2_32", "iphlpapi"],
                   extra_objects=[r"msvc\Release\upnpc-static.lib"])
      ])


Let me ask this: if I already need to compile the project to produce the upnpcxxxx.lib file, why does python need to compile the sources a second time? And there were two projects in the solution, the upnpc-static project is the correct one to feed the extra_objects argument, above, right?

This is quite a learning adventure,
-Stat
Back to top
View user's profile Send private message
miniupnp
Site Admin


Joined: 14 Apr 2007
Posts: 1589

PostPosted: Mon Oct 26, 2015 9:14 am    Post subject: Reply with quote

I just don't know how building Python modules under Win32 works.
Everything works well under Linux and Mac OS X with the Makefile :
$ make installpythonmodule
and that's all Smile
_________________
Main miniUPnP author.
https://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: 1589

PostPosted: Thu Apr 26, 2018 9:25 pm    Post subject: Reply with quote

I have managed to get Appveyor build the python modules. get them here :
https://ci.appveyor.com/project/miniupnp/miniupnp/build/artifacts
_________________
Main miniUPnP author.
https://miniupnp.tuxfamily.org/
Back to top
View user's profile Send private message Visit poster's website
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.