tobspr / P3DModuleBuilder

Toolkit to make C++ modules and extensions for the Panda3D engine
MIT License
20 stars 12 forks source link

Compile Error - Subdirectories not handled #4

Open zauberparacelsus opened 8 years ago

zauberparacelsus commented 8 years ago

I attempted to use P3DModuleBuilder with a C++ library that implements the Cubical Marching Squares algorithm, and ran into a compiler error:

Process error:

  *** Error in ./cubical-marching-squares/include/vec3.h near line 31, column
  16:

  syntax error, unexpected KW_STATIC

  Error parsing file: './cubical-marching-squares/include/cell.h'

I'll note that the CMS library compiles normally on its own. Would it be possible to 'trick' P3DModuleBuilder by copying over the compiled libCMS.a file?

The library in question is at: https://bitbucket.org/GRassovsky/cubical-marching-squares

rdb commented 8 years ago

This is a bug in interrogate. I'll look into it, but in the meantime, you can edit the vec3.h file referenced in the error message and change "const static" to "static const" on line 31.

You can also put #ifndef CPPPARSER around the includes to the CMS library, which might work as well.

zauberparacelsus commented 8 years ago

Thanks. That got me past the configure phase, but then I got a fatal error about a file missing. Apparently, the error was due to this library having the header files stored in a separate directory.

So, I did a make clean (IE: deleted the build folder) and then moved the header files into the same directory as the source files. It got a tiny bit further, but now it is complaining about another file that doesn't exist, despite it existing:

[  5%] Building CXX object CMakeFiles/CMS.dir/source/interrogate_module.cpp.o
[ 10%] Building CXX object CMakeFiles/CMS.dir/source/cubical-marching-squares/src/cell.cpp.o
[ 15%] Building CXX object CMakeFiles/CMS.dir/source/interrogate_wrapper.cpp.o
[ 21%] Building CXX object CMakeFiles/CMS.dir/source/cubical-marching-squares/src/vec3.cpp.o
[ 26%] Building CXX object CMakeFiles/CMS.dir/source/config_module.cpp.o
[ 31%] Building CXX object CMakeFiles/CMS.dir/source/cubical-marching-squares/src/address.cpp.o
[ 36%] Building CXX object CMakeFiles/CMS.dir/source/cubical-marching-squares/src/octree.cpp.o
/home/zauber/Paracosm/pyParacosm/cpp/P3DModuleBuilder/source/interrogate_wrapper.cpp:38:21: fatal error: address.h: No such file or directory
compilation terminated.
CMakeFiles/CMS.dir/build.make:62: recipe for target 'CMakeFiles/CMS.dir/source/interrogate_wrapper.cpp.o' failed
make[2]: *** [CMakeFiles/CMS.dir/source/interrogate_wrapper.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/CMS.dir/all' failed
make[1]: *** [CMakeFiles/CMS.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
zauberparacelsus commented 8 years ago

I managed to get it to build. The source files were all in a subfolder, like so:

P3DModuleBuilder
  \_source
    \_cubical-marching-squares
      \_src

Moving the contents of the src directory two levels up to the source directory fixed the issue.

And that probably exposes another issue in Interrogate: that it has trouble picking up on headers stored in subdirectories.

rdb commented 8 years ago

Hmm, seems more like a missing argument to reference the directory on the interrogate command-line. To be honest I'm not really familiar with how the modulebuilder handles additional include directories.

For what it's worth, I checked in a fix for the interrogate parser issue to panda3d/panda3d@db977479813d0e524f36613f44cf49038dbf4bcc .

zauberparacelsus commented 8 years ago

Okay, it compiled, but when I actually tried using it, I found that it did not include anything from the library's namespace, despite the correct files having shown up in the compile output.

If I run dir(CMS), I just see the following:

['Dtool_PyNativeInterface', '__doc__', '__file__', '__name__', '__package__']

Trying to run "from CMS import ..." on any of the known classes, such as cell, octree, or array3d just returns an ImportError.

tobspr commented 8 years ago

Right now the CMake script only adds the panda include directory to the include path, and the root directory of the source/ folder. One would have to modify scripts/interrogate.py to recursively collect all headers (I think modifying find_sources(base_dir) should probably already be enough).

The classes are not exposed because the PUBLISHED: keyword is not used. You should replace the public:keyword with PUBLISHED: in every class you want to expose.

rdb commented 8 years ago

If you want to expose the classes without modifying the headers, you can run interrogate in -promiscuous mode, or you can create a .N file containing instructions like "forcetype SomeClass". See the .N files in the Panda source code base for examples.

zauberparacelsus commented 8 years ago

I tried changing the public: keyword to published:, but it resulted in compile errors. I also tried tweaking the interrogate wrapper script to include the promiscuous flag. It compiled, but I get an import error now:

>>> from panda3d.core import *
>>> import CMS
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./CMS.so: undefined symbol: Dtool_NotifyCategoryProxy_NotifyCategoryGetCategory_mymodule