Trying to get it to work with c++

Hey,

I’m trying to get panda to work in c++, cuz’ i want to write some documentation about it.

But, I can’t seem to import some files:

#import </usr/share/panda3d/direct/src/directbase/directbase.cxx>

The g++ compiler complains about a missing pandabase.h file.
I also tried importing directbase.h instead of .cxx. Same result.
Where can I find that file?

ok, i found them in a directory at the other side of the world, at /usr/include/panda3d.
But, now, when I include the appropiate filed, it throws in a couple of millions of file not found errors.
What can be wrong?

OK, well, first you shouldn’t be including the .cxx files. Only include the .h files.

Second, you can’t specify the full path like this, since the Panda files won’t know where to find the other Panda files. Instead, set your INCLUDE path on your compiler (with gcc, this means with the -I command-line option) to point to the appropriate path, and then just #include “directbase.h”.

David

Thanks for the help, this works now.
The only problem now is: How to open the panda3d window?
There is no directstart.h file. I can’t call run.

I looked at the pview.cxx file, but if I try to compile that one it gives me a few million errors. (looks like first a few missing file-errors, then a bunch of syntax errors???)

Welcome to the world of C++ development. You’ll have to do a bit more by hand in C++. There’s no DirectStart. There’s no run(). And when you get a syntax error in the compiler, the error message is likely to be almost completely meaningless.

The code in pview.cxx uses a C+±only library called framework. It defines the classes PandaFramework and WindowFramework, which more or less take the place of DirectStart and run(). You’ll need to use these classes to make it work.

If you can’t cut-and-paste from pview.cxx and compile successfully, something’s wrong. What is the first missing header file? There shouldn’t be any missing files.

David

I import pandaframework.h.
The first few lines of the error message:

In file included from /usr/include/panda3d/atomicAdjustDummyImpl.h:25,
                 from /usr/include/panda3d/atomicAdjust.h:27,
                 from /usr/include/panda3d/deletedChain.h:25,
                 from /usr/include/panda3d/pallocator.h:24,
                 from /usr/include/panda3d/pvector.h:25,
                 from /usr/include/panda3d/typeRegistry.h:25,
                 from /usr/include/panda3d/typeHandle.h:23,
                 from /usr/include/panda3d/cycleData.h:23,
                 from /usr/include/panda3d/pandaNode.h:24,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:4:
/usr/include/panda3d/numeric_types.h:35:21: error: prtypes.h: No such file or directory
In file included from /usr/include/panda3d/connection.h:24,
                 from /usr/include/panda3d/netDatagram.h:24,
                 from /usr/include/panda3d/connectionManager.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:28,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:4:
/usr/include/panda3d/netAddress.h:25:18: error: prio.h: No such file or directory
In file included from /usr/include/panda3d/netDatagram.h:24,
                 from /usr/include/panda3d/connectionManager.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:28,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:4:
/usr/include/panda3d/connection.h:27:20: error: prlock.h: No such file or directory
/usr/include/panda3d/connection.h:28:21: error: prerror.h: No such file or directory
In file included from /usr/include/panda3d/queuedConnectionReader.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:29,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:4:
/usr/include/panda3d/connectionReader.h:29:22: error: prthread.h: No such file or directory
In file included from /usr/include/panda3d/connectionWriter.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:30,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:4:
/usr/include/panda3d/datagramQueue.h:27:20: error: prcvar.h: No such file or directory
In file included from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:4:
/usr/include/panda3d/pandaNode.h:54:20: error: Python.h: No such file or directory

pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6: error: ‘WindowFramework’ was not declared in this scope
main.cpp:6: error: ‘window’ was not declared in this scope
main.cpp:6: error: ‘framework’ was not declared in this scope
pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6: error: ‘framework’ was not declared in this scope
main.cpp:8: error: ‘WindowFramework’ was not declared in this scope
main.cpp:8: error: ‘window’ was not declared in this scope
pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
main.cpp:3: error: ‘PandaFramework’ does not name a type
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6: error: ‘framework’ was not declared in this scope
main.cpp:8: error: ‘WindowFramework’ was not declared in this scope
main.cpp:8: error: ‘window’ was not declared in this scope
pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
main.cpp:1:26: error: pandaFramework: No such file or directory
main.cpp:4: error: ‘PandaFramework’ does not name a type
main.cpp: In function ‘int main(int, char**)’:
main.cpp:7: error: ‘framework’ was not declared in this scope
main.cpp:9: error: ‘WindowFramework’ was not declared in this scope
main.cpp:9: error: ‘window’ was not declared in this scope
pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
main.cpp:3: error: ‘PandaFramework’ does not name a type
main.cpp: In function ‘int main(int, char**)’:
main.cpp:6: error: ‘framework’ was not declared in this scope
main.cpp:8: error: ‘WindowFramework’ was not declared in this scope
main.cpp:8: error: ‘window’ was not declared in this scope
pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
In file included from /usr/include/panda3d/atomicAdjustDummyImpl.h:25,
                 from /usr/include/panda3d/atomicAdjust.h:27,
                 from /usr/include/panda3d/deletedChain.h:25,
                 from /usr/include/panda3d/pallocator.h:24,
                 from /usr/include/panda3d/pvector.h:25,
                 from /usr/include/panda3d/typeRegistry.h:25,
                 from /usr/include/panda3d/typeHandle.h:23,
                 from /usr/include/panda3d/cycleData.h:23,
                 from /usr/include/panda3d/pandaNode.h:24,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/numeric_types.h:35:21: error: prtypes.h: No such file or directory
In file included from /usr/include/panda3d/connection.h:24,
                 from /usr/include/panda3d/netDatagram.h:24,
                 from /usr/include/panda3d/connectionManager.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:28,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/netAddress.h:25:18: error: prio.h: No such file or directory
In file included from /usr/include/panda3d/netDatagram.h:24,
                 from /usr/include/panda3d/connectionManager.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:28,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/connection.h:27:20: error: prlock.h: No such file or directory
/usr/include/panda3d/connection.h:28:21: error: prerror.h: No such file or directory
In file included from /usr/include/panda3d/queuedConnectionReader.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:29,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/connectionReader.h:29:22: error: prthread.h: No such file or directory
In file included from /usr/include/panda3d/connectionWriter.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:30,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/datagramQueue.h:27:20: error: prcvar.h: No such file or directory
In file included from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/pandaNode.h:54:20: error: Python.h: No such file or directory

pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ -I/usr/include/panda3d/ main.cpp
In file included from /usr/include/panda3d/atomicAdjustDummyImpl.h:25,
                 from /usr/include/panda3d/atomicAdjust.h:27,
                 from /usr/include/panda3d/deletedChain.h:25,
                 from /usr/include/panda3d/pallocator.h:24,
                 from /usr/include/panda3d/pvector.h:25,
                 from /usr/include/panda3d/typeRegistry.h:25,
                 from /usr/include/panda3d/typeHandle.h:23,
                 from /usr/include/panda3d/cycleData.h:23,
                 from /usr/include/panda3d/pandaNode.h:24,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/numeric_types.h:35:21: error: prtypes.h: No such file or directory
In file included from /usr/include/panda3d/connection.h:24,
                 from /usr/include/panda3d/netDatagram.h:24,
                 from /usr/include/panda3d/connectionManager.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:28,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/netAddress.h:25:18: error: prio.h: No such file or directory
In file included from /usr/include/panda3d/netDatagram.h:24,
                 from /usr/include/panda3d/connectionManager.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:28,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/connection.h:27:20: error: prlock.h: No such file or directory
/usr/include/panda3d/connection.h:28:21: error: prerror.h: No such file or directory
In file included from /usr/include/panda3d/queuedConnectionReader.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:29,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/connectionReader.h:29:22: error: prthread.h: No such file or directory
In file included from /usr/include/panda3d/connectionWriter.h:24,
                 from /usr/include/panda3d/pStatClientImpl.h:30,
                 from /usr/include/panda3d/pStatClient.h:25,
                 from /usr/include/panda3d/pStatThread.h:24,
                 from /usr/include/panda3d/pStatCollector.h:24,
                 from /usr/include/panda3d/renderState.h:29,
                 from /usr/include/panda3d/pandaNode.h:31,
                 from /usr/include/panda3d/nodePath.h:24,
                 from /usr/include/panda3d/windowFramework.h:23,
                 from /usr/include/panda3d/pandaFramework.h:24,
                 from main.cpp:2:
/usr/include/panda3d/datagramQueue.h:27:20: error: prcvar.h: No such file or directory

I get two million more.

Don’t let the sheer number of errors daunt you. In C++, you often get gazillions of errors. Only the first one usually matters, since one error will tend to cause lots of other errors.

In this case, the problem is prtypes.h, which it wasn’t able to find. This file is part of NSPR, and is one of the third-party libraries. You need to make sure that all of the third-party header files are also available on the INCLUDE path.

Are you sure you want to be doing this C++ work? It will be difficult going unless you already have a lot of experience with C++.

David

Where can I download those third-party files?
(I can’t find the files anywhere on my PC (linux))

Well… if nobody writes manual pages about that, I’ll have to do it…
I have a little bit experience in C++, but not so much. But I do want to give it a try.

You can download them from the software download page here.

I’m glad to see such enthusiasm. Please continue. But you should be aware that Panda in C++ is not really well-suited for the C++ newcomer. This is why we also provide Panda in Python. :slight_smile:

David

Thanks!:slight_smile:

I made some progress. I downloaded the tar package, extracted it, added to the -I parameter at my commandline.
Still, a lot of file-not-found errors. Some of the source files import from a dir called “obsolete/file.h”, but the obsolete dir doesn’t exists. So, I copied all files into an /obsolete/ folder I just created and now that works.
Again, it asks for Python.h (i have no idea to set the g++ include path to recursive)
I copied that one from dtool/src/parser-inc to the main dir, now that works, but now i get the following error:

/usr/include/panda3d/nodePath.I: In member function ‘PyObject* NodePath::get_python_tag(const std::string&) const’:
/usr/include/panda3d/nodePath.I:2242: error: ‘Py_RETURN_NONE’ was not declared in this scope

That’s the only error I get right now.

But ehrr. I’m not using any python at all. Weird?

Anyone knows how to fix this, and why I get this anyway?

This is a Python version thing. Panda 1.3.2 made a reference to Py_RETURN_NONE, which is only defined in Python version 2.4 or later. If you have an earlier version of Python, this code is not compatible.

You can either upgrade your version of Python, or you can download the latest version of Panda from CVS (which removes this reference, and therefore supports earlier versions of Python).

By the way, you shouldn’t need to copy header files around. You should instead put every needed directory on the gcc command line with -I.

David

Thanks.

But… I deleted my old source files and downloaded the new one from cvs.
Now, I can’t find those *** third-party files anywhere.
I do need prtypes.h otherwise I can’t include the pandaFramework.h.
Where can I get that one?
Or do I just need the old thirdparty files of version 1.3.2?

By the way. -I does not work recursive, does it?

You have to download the third-party files from the website–they’re not part of the CVS repository. Josh has assembled those by hand and put them into a convenient tarball. Use the version from 1.3.2.

No, -I does not work recursively. You must explicitly specify each subdirectory that needs to be on the list. Incidentally, the makepanda script sets up the -I paths correctly. You might take a look at what that script is doing.

David

I tried it, but it’s too much work. So, I put all the include files in 1 directory. Now, it squeals for a few more not found files:
dtool_config.h and strstream.h
I looked for them myself, but couldn’t find them anywhere, not even in the third-party libraries.

Additionally, I receive this error:

/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.

Maybe it would be helpful to build Panda from scratch first, using the provided makepanda script? When you have successfully built your own copy of Panda, you will have learned a lot about how the compiler is intended to be configured for building C++ code in conjunction with Panda, from watching the way the makepanda script does it.

David

Ok, I’ll try to compile it using makepanda tomorrow. (It’s 20:5 here, and I’m very tired.)
But hmm… those two missing files, dtool_config.h and strstream.h, I looked on my entire computer for those, but couldn’t find them… where can I find those two files?

dtool_config.h is a generated file. It is generated by makepanda, or by ppremake, according to the specifications of your computer.

One of the things that dtool_config.h defines is whether your computer has a strstream.h (an older C++ convention) or stringstream (a newer C++ convention). If it’s not loading dtool_config.h at all, I can certainly imagine it would then get confused and try to load strstream.h even though your system doesn’t have it.

David

Thanks drwr, makepanda helped a lot!

But, now I get the following errors:

pro-rsoft@REINIER:~/docs/Programmeren/Programs/pandacpp$ g++ pview.cxx -I /home/pro-rsoft/docs/Programmeren/Programs/pandacpp/thirdparty/linux-libs-a/nspr/include/ -I /usr/include/panda3d -I "/usr/include/python2.5" -L "/usr/lib/python2.5" -L /home/pro-rsoft/docs/Programmeren/Programs/pandacpp/thirdparty/linux-libs-a/nspr/lib/ 
/tmp/ccKgIjgu.o: In function `__static_initialization_and_destruction_0(int, int)':
pview.cxx:(.text+0xf8): undefined reference to `PandaFramework::PandaFramework()'
/tmp/ccKgIjgu.o: In function `__tcf_3':
pview.cxx:(.text+0x3c2): undefined reference to `PandaFramework::~PandaFramework()'
/tmp/ccKgIjgu.o: In function `report_version()':
pview.cxx:(.text+0x421): undefined reference to `Notify::out()'

...etc... much more errors...

I think this is because I didn’t link to the libraries, is this right?

Right, you will need to link with the various dtool libraries.

David