[SOLVED] Issue with Linking Panda classes with Interrogate

Dear all -

Using the tutorial from Tobias (many thanks to Tobias for putting this!) at [Guide] Interrogate in 8 steps, I manage to do the first part working (a method with ‘printf’ usable by Python code) but I don’t manage to do the next part with Panda classes (e.g. LVecBase3d or Nodepath); since a linker error is occuring:

(LNK2001	external symbol not resolved  "__declspec(dllimport) bool __cdecl Dtool_Coerce_LVecBase3d(struct _object *,class LVecBase3d * &,bool &)" (__imp_?Dtool_Coerce_LVecBase3d@@YA_NPEAU_object@@AEAPEAVLVecBase3d@@AEA_N@Z)	TestInterrogate	XXXX\TestInterrogate\TestInterrogate_igate.obj	

Using:
Win7 64 / 1.9.0 Official Build [UPDATE: same operations to be done for 1.9.1 official build - see below]
VS 2015
I also managed to compile normal Panda / C++ samples using the same settings.

Command to launch interrogate:

interrogate -v -D__inline -DCPPPARSER -DP3_INTERROGATE=1 -D__cplusplus -fnames -string -refcount -assert -S"xxx\PandaSDK\Panda3D-1.9.0-x64\include\parser-inc" -S"xxxx\PandaSDK\Panda3D-1.9.0-x64\include" -I"xxx\PandaSDK\Panda3D-1.9.0-x64\include" -oc TestInterrogate_igate.cxx -od TestInterrogate.in -python-native *.h -module TestInterrogate -library TestInterrogate -Dvolatile=

interrogate_module -python-native -module TestInterrogate -library TestInterrogate -oc TestInterrogate_module.cxx TestInterrogate.in

Attached: Interrogate detailed log - Many thanks!
Interrogate.txt (5.53 KB)

Oh, I completely forgot about that tutorial! :stuck_out_tongue: Theres alot of wrong stuff in it (now I know it better), I guess I should fix that at some time.

I’m not sure whats exactly going on (rdb probably knows way better), but can you ensure you linked to all panda libraries? IIRC those are:

python27.lib
libp3framework.lib
libpanda.lib
libpandaexpress.lib
libp3dtool.lib
libp3dtoolconfig.lib
libp3direct.lib
libp3interrogatedb.lib

Thanks Tobias - your tutorial was indeed very useful to start with!

I tested to link with the library list you proposed but unfortunately the “libp3interrogatedb.lib” (I saw this one in a previous post- see Need core.so/.lib when linking in 1.9?) isn’t available in the official 1.9.0. (I don"t see it in the lib directory of Panda).

According to the aforementioned post, it seems that it has been added after official 1.9.0 release (if I understand correctly). I would suspect interrogate dependencies are located in an other lib. for the official 1.9.0.

If I stay with the 7 other libs you mentionned,the result is the same: the linker doesn’t resolve the LVecBase3d symbol.

Thanks again

In 1.9.0, you must link to core.lib, which will create a link-time dependency on core.pyd, which hosts the core Panda bindings.

I really recommend you to grab the latest development build of Panda, if you can. The interrogate interface has been improved dramatically recently, with the compilation and linking procedure being made easier, as well as improved diagnostics when things go wrong.

In particular, it no longer requires you to link to Panda’s Python bindings, instead only requiring you to link with libp3interrogatedb.lib, and making sure that panda3d.core has been imported first (which you can ensure by adding “-import panda3d.core” to the interrogate_module command line).

Many thanks.

Sorry for the (probably very silly) question, but where is located the core.lib in 1.9.0? I can’t find it in the lib directory; I also tried to use the core.pyd (renaming it in core.lib) located in the panda3d directory, but VS doesn’t like it and states that this file is corrupted or can’t be read.

As for your suggestion to use the latest dev build (although I was not in favor of that, since I prefer to use more stabilized versions), I’ll certainly do it to test since it may probably help.

Thanks again.

Drat, it is indeed missing from 1.9.0. You can generate a .lib file from a .pyd file using a method like this. (.pyd files are really .dll methods in disguise). Note that you may have to change the /machine:x86 part in that article to x64 if you’re using a 64-bit installation.

Thanks rdb, that makes sense.

I tried your suggestion and managed to convert core.pyd into core.lib. I have no more error during the linking (good!) but now when I import the module, it says: "ImportError: DLL load failed: the specified module can’t be found’ which I understand shows that some dependencies are missing.

So I made a “dumpbin /dependents TestInterrogate.pyd” to see what are the depencies of the generated module.

Result:

   libpanda.dll
   libp3dtool.dll
   libp3dtoolconfig.dll
   core.dll
   python27.dll
   KERNEL32.dll
   VCRUNTIME140.dll
   api-ms-win-crt-stdio-l1-1-0.dll
   api-ms-win-crt-runtime-l1-1-0.dl
   api-ms-win-crt-heap-l1-1-0.dll

I am bit surprised that ‘libpanda’, ‘libp3dtool’, ‘core’,… have an extension in ‘dll’ and not ‘lib’. I don’t know if that may be the root cause.

In addition, I added in the PATH some additional directories to make sure Python will scan the appropriate ones, but unfortunately no change.

Any more idea? I’ll probably switch sooner than expected to the 1.10 version if that may make things easier :slight_smile:

Thanks again.

Yes, they are supposed to have .dll extensions. The Panda dlls can be found in the bin directory of the Panda3D SDK.

The problem is the core.dll in the list, however, which should be core.pyd. I think you may have to specify something like /name:core.pyd to the “lib” command you used to generate the .lib, to indicate the correct name of the library.

Excellent,it now works ! Many thanks rdb and Tobias.

So I decided to sum up some complement of information to Tobias’ tutorial (originally for Panda 1.8.1 / Visual Studio 2008 – see [Guide] Interrogate in 8 steps) for the following configuration:

  • Panda x64 1.9.0/1.9.1 (official build)
  • Visual studio 2015 (VS)
  • Windows 7/x64

Warning: as said by rdb in this thread, latest versions of Panda SDK have a more robust Interrogate interface. So this short memo is only intended for those who want to use Interrogate with the aforementioned configuration.

EDIT : Tobias made a tool that performs Step 1 / Step 3 of this memo in a complete automated way - see
https://discourse.panda3d.org/viewtopic.php?t=18420
However, should you run 1.9.0 or 1.9.1,you still need to perform Step 2 (generation of core.lib- see below) and Step 3.A in order to make it work.

  1. Step 1: Perform first steps from Tobias’ tutorial- Interrogate without integration with P3D classes
    Follow the steps 1 to 7. Make sure you obtain the appropriate ‘Hello World’: if not, go back to the previous steps.

[i]Note #1
Interrogate will work only if the solution/project have been correctly setup in the VS 2015 context. This is described in the following manual page: panda3d.org/manual/index.ph … nguage=cxx
As a reminder, the key points to check:

  • Solution in Release version and x64
  • “Platform Toolset” in the “General” tab to “Visual Studio 2015 - Windows XP (v140_xp)”
  • NDEBUG to be removed from preprocessor
  • Libraries to link:

libp3framework.lib
libpanda.lib
libpandaexpress.lib
libp3dtool.lib
libp3dtoolconfig.lib
libp3direct.lib
[/i]

[i]Note #2
Interrogate seems to be sensitive (at least for the 1.9.0 version) so you’ll need to:

  • Remove the #pragma once directives that VS will have created automatically in stdafx.h – see panda3d.org/forums/viewtopic … 12&t=16162
  • Comment out completely dllmain.cpp
  • Check the generated code (the .cxx), at least to control that the methods you want to bind with Python have been taken into account
  • Put the ‘-v’ flag (verbose mode) on the interrogate command line at step 3 (should you have any need to see what happens).
    [/i]
  1. Step 2: Generate core.lib – specific to 1.9.0 / 1.9.1

If you decided to continue and perform Tobias’ tutorial step 8 (Integrate with Panda3D), you would have found out that there is a systematic error with the linker, since no Panda classes can be found. In 1.9.0, the specific library ‘core.lib’ should be linked with your program in order the code to be successfully compiled.

Unfortunately, this lib is not ‘directly’ included in 1.9.0: there is however a workaround. It consists in using the ‘core.pyd’ (located in the “panda3d” directory of your P3D install directory) and transform it into a readable lib for the VS linker.

Rdb suggested this tutorial which perfectly works – see wiki.videolan.org/GenerateLibFromDll.

Steps to perform:

2.A. Copy the ‘core.pyd’ to the directory where you want to perform the steps of the wiki.videolan tutorial, use the Visual Studio Tools and change (cd) to this directory

2.B. Follow the different steps described in the tutorial with 2 important modifications to do in the step ‘Generate the .lib’

  • Set ‘/machine:x64’ instead of ‘/machine:x86’
    -Add the ‘/name:core.pyd’ to the command line. If not added, it will be not possible to import your module into the python code

You should now have a file ‘core.lib’ that is ready to be linked with your Interrogate code.

[i]Note #1
During the step ‘Extract Symbols’, if you choose the manual edit of the core.def file, you only need to:

  • Add EXPORTS (capital letter AND plural!) at the first line
  • Remove all columns except the last one (Excel can be used to do it quickly)

The beginning of the ‘core.def’ file should look like:
EXPORTS
??4?$Extension@V?$ConstPointerToArray@E@@@@QEAAAEAV0@AEBV0@@Z
??4?$Extension@V?$ConstPointerToArray@G@@@@QEAAAEAV0@AEBV0@@Z
??4?$Extension@V?$ConstPointerToArray@H@@@@QEAAAEAV0@AEBV0@@Z
??4?$Extension@V?$ConstPointerToArray@M@@@@QEAAAEAV0@AEBV0@@Z
??4?$Extension@V?$ConstPointerToArray@N@@@@QEAAAEAV0@AEBV0@@Z
??4?$Extension@V?$ConstPointerToArray@VLMatrix3d@@@@@@QEAAAEAV0@AEBV0@@Z
??4?$Extension@V?$ConstPointerToArray@VLMatrix3f@@@@@@QEAAAEAV0@AEBV0@@Z

[/i]
3. Step 3: Move core.lib and compile Panda classes – specific to 1.9.0 / 1.9.1

Perform the following steps:

3.A. Put the “core.lib” into the ‘lib’ directory of your P3D install

3.B. Add ‘core.lib’ in the VS linker libraries. You should now have:
[list]
libp3framework.lib
libpanda.lib
libpandaexpress.lib
libp3dtool.lib
libp3dtoolconfig.lib
libp3direct.lib
core.lib

3.C. Perform Step 8 of Tobias’s tutorial and ensure the output is correct.[/list:u]

Done: start developing more complex code!