[Solved] Linking problem while compiling Cython module in command prompt with Panda3D 1.10-x64 on Windows 10


#1

I’m trying to port my python 2.7 Panda app to 3.7 while upgrading from Panda 1.9 to 1.10-x64.

Eventually I want to build my installer using deploy-ng.

My first step is to be able to compile Cython modules with the new compiler.

After downloading VC++ 2015, I can now compile and run a Cython hello world.

I try compiling my app, which includes several Cython modules.

It gets through some of them. However, after compiling one of them, it has trouble linking.

The compilation command shown below runs fine, with a few warnings here and there. Note that newlines are added for readability:

running build_ext
skipping 'path\to\module.cpp' Cython extension (up-to-date)
building 'module' extension

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe 
    /c /nologo /Ox /W3 /GL /DNDEBUG /MT 
    -IC:\Panda3D-1.10.0-x64\include 
    -IC:\Panda3D-1.10.0-x64\python\include 
    -IC:\Panda3D-1.10.0-x64\python\include 
   "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" 
   "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" 
   "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" 
    /EHsc /Tppath\to\module.cpp /Fobuild\temp.win-amd64-3.7\Release\path\to\module.obj /EHsc -DNDEBUG

module.cpp

...series of warnings.....

The linking command has trouble though:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe 
    /nologo /INCREMENTAL:NO /LTCG /nodefaultlib:libucrt.lib ucrt.lib /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO 
    /LIBPATH:C:\Panda3D-1.10.0-x64\python\libs 
    /LIBPATH:C:\Panda3D-1.10.0-x64\lib 
    /LIBPATH:C:\Panda3D-1.10.0-x64\python\libs 
    /LIBPATH:C:\Panda3D-1.10.0-x64\python\PCbuild\amd64 
   "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" 
   "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" 
   "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" 
   "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" 
   "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" libpanda.lib 
   /EXPORT:PyInit_module build\temp.win-amd64-3.7\Release\path\to\module.obj 
   /OUT:c:\Users\<user>\path\to\pandapp\module.cp37-win_amd64.pyd 
   /IMPLIB:build\temp.win-amd64-3.7\Release\path\to\module.cp37-win_amd64.lib

module.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int panda_version_1_10" (__imp_?panda_version_1_10@@3HA)
c:\Users\<user>\path\to\pandapp\module.cp37-win_amd64.pyd : fatal error LNK1120: 1 unresolved externals
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\BIN\\amd64\\link.exe' failed with exit status 1120

Any ideas? I’m pretty much stumped here.

I noticed that the folder

C:\Panda3D-1.10.0-x64\python\PCbuild\

does not exist, even after reinstalling.

Perhaps something is wrong with my installation?

I got the build tools for MSVS 2017. With that I installed:

  • .NET 4.7 SDK and Targeting Pack.
  • C++/CLI Support
  • VC++ 2015.3 v14.00 (v140) toolset for desktop
  • VC++ 2017 version 15.9 v14.16 latest v141 tools
  • Windows 10 SDK 10.0.10240.0

I also installed Visual Studio Community 2017 (2) 15.9.5 along with similar things as above:

  • C++/CLI Support
  • Windows 10 SDK 10.0.17134.0
  • Windows 10 SDK 10.0.17763.0
  • Visual C++ 2017 Redistributable Update
  • VC++ 2015.3 v14.00 (v140) toolset for Desktop
  • VC++ 2017 version 15.9 v14.16 latest v141 tools

However, I’ve been running my app’s build script from the command line.

The PATH variable in my VS2015 x64 Native Tools Command Prompt is:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64
C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools
C:\Program Files (x86)\HTML Help Workshop
C:\Program Files (x86)\Windows Kits\10\bin\x64
C:\Program Files (x86)\Windows Kits\10\bin\x86
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\x64\
C:\Program Files (x86)\Intel\iCLS Client\
C:\Program Files\Intel\iCLS Client\
C:\Windows\system32
C:\Windows
C:\Windows\System32\Wbem
C:\Windows\System32\WindowsPowerShell\v1.0\
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\Intel\WiFi\bin\
C:\Program Files\Common Files\Intel\WirelessCommon\
C:\WINDOWS\system32
C:\WINDOWS
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\
C:\WINDOWS\System32\OpenSSH\
C:\Program Files\Git\cmd
C:\Program Files\dotnet\
C:\Users\Provel\AppData\Local\Microsoft\WindowsApps
C:\bin
C:\Program Files (x86)\Panda3D\
C:\Panda3D-1.10.0-x64\python
C:\Panda3D-1.10.0-x64\python\Scripts
C:\Panda3D-1.10.0-x64\bin

#2

What’s missing is that it’s not linking to the Panda libraries. I don’t see libpanda.lib, libp3dtool.lib, etc. mentioned on the linker command-line.


#3

The libpanda.lib is at the end of the last /LIBPATH but I’m not seeing the libp3dtool.lib or whatnot either.

Would what I import in the cython file affect which .lib files are on the linker command?

I’m only importing from panda3d.core


#4

Were you previously able to compile this without linking directly to the Panda libraries?

You need to link to libp3dtool.lib and libp3dtoolconfig.lib by adding those to the linker command-line. I’m surprised if it worked without that otherwise.


#5

Ok,

Let me check. I’d need to return to that setup or find an old compile log.

But probably as usual I’m the one with the strange installation or something.


#6

Ok, I reinstalled Panda3D 1.9.4 32bit and recompiled everything and got my app to run

C:\Users\<user>\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\cl.exe 
    /c /nologo /Ox /MD /W3 /GS- /DNDEBUG -IC:\Panda3D-1.9.4\include 
    -IC:\Panda3D-1.9.4\python\include 
    -IC:\Panda3D-1.9.4\python\PC 
    /Tpapi\module\module.cpp /Fobuild\temp.win32-2.7\Release\path\to\module.obj /EHsc -DNDEBUG

....string of warnings....

C:\Users\<user>\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\VC\Bin\link.exe 
    /DLL /nologo /INCREMENTAL:NO /LIBPATH:C:\Panda3D-1.9.4\python\libs 
    /LIBPATH:C:\Panda3D-1.9.4\lib 
    /LIBPATH:C:\Panda3D-1.9.4\python\libs 
    /LIBPATH:C:\Panda3D-1.9.4\python\PCbuild 
    /LIBPATH:C:\Panda3D-1.9.4\python\PC\VS9.0 libpanda.lib 
    /EXPORT:initmodule build\temp.win32-2.7\Release\api\module\module.obj 
    /OUT:c:\Users\<user>\path\to\pandapp\module.pyd 
    /IMPLIB:build\temp.win32-2.7\Release\path\to\module.lib 
    /MANIFESTFILE:build\temp.win32-2.7\Release\path\to\module.pyd.manifest
   Creating library build\temp.win32-2.7\Release\path\to\module.lib and object build\temp.win32-2.7\Release\api\module\module.exp
  tree = Parsing.p_module(s, pxd, full_module_name)

Its still just using libpanda.lib and I’ve confirmed that basic functionality of my app works

I’ve also instantiated a panda3d.core.Vec3 in my Cython helloworld and here’s the compile/link commands

Compiling helloworld.pyx because it changed.
[1/1] Cythonizing helloworld.pyx
running build_ext
building 'helloworld' extension
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\cl.exe 
    /c /nologo /Ox /W3 /GL /DNDEBUG /MT 
    -IC:\Panda3D-1.10.0-x64\python\include 
    -IC:\Panda3D-1.10.0-x64\python\include 
   "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE" 
   "-IC:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\INCLUDE" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" 
   "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" 
   "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" 
    /Tchelloworld.c /Fobuild\temp.win-amd64-3.7\Release\helloworld.obj

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\BIN\amd64\link.exe 
    /nologo /INCREMENTAL:NO /LTCG /nodefaultlib:libucrt.lib ucrt.lib /DLL 
    /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO 
    /LIBPATH:C:\Panda3D-1.10.0-x64\python\libs 
    /LIBPATH:C:\Panda3D-1.10.0-x64\python\PCbuild\amd64 
    "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\LIB\amd64" 
    "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\ATLMFC\LIB\amd64" 
    "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\ucrt\x64" 
    "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\lib\um\x64" 
    "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.17763.0\um\x64" 
    /EXPORT:PyInit_helloworld build\temp.win-amd64-3.7\Release\helloworld.obj 
    /OUT:c:\Users\<user>\path\to\practice\cython\CythonHelloWorld\helloworld.cp37-win_amd64.pyd 
    /IMPLIB:build\temp.win-amd64-3.7\Release\helloworld.cp37-win_amd64.lib
helloworld.obj : warning LNK4197: export 'PyInit_helloworld' specified multiple times; using first specification
   Creating library build\temp.win-amd64-3.7\Release\helloworld.cp37-win_amd64.lib and object build\temp.win-amd64-3.7\Release\helloworld.cp37-win_amd64.exp
Generating code
Finished generating code
C:\Panda3D-1.10.0-x64\python\lib\site-packages\Cython\Compiler\Main.py:367: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: c:\Users\<user>\path\to\practice\cython\CythonHelloWorld\helloworld.pyx
  tree = Parsing.p_module(s, pxd, full_module_name)

#7

I think the change that caused this is this one:

Is it not working to add libp3dtoolconfig.lib and libp3dtool.lib to your linker command-line? If not, what error do you get when you do this?


#8

Oh ok,

Yeah, let me try that.


#9

Ok, cython compilation works!

I figured out the gist also. Basically find the function/class name from the link error, find that in the cxx docs, and figure out which .lib file its in based on which .h file.

Thanks rdb, this was really helpful