I spent quite a bit of time searching on the forums and in the manual for simple step-by-step instructions for compiling a simple c++ app in visual studio that links against panda without having to rebuild everything.
I finally found what I needed buried in the following topics:
While I was searching I noticed a lot of people seem interested in this topic. Here, I’d like to record my experience starting from scratch in the hope that it will help future panda3d c++ developers.
In which I outline all of the prepatory steps you should take to before embarking.
1.) You should have panda 3d installed via the regular panda3d install package. (The version I am using is: Panda3D-1.2.3).
2.) You should have the source code to pview.cxx. This is a simple model viewer app that comes w/panda. It also seems to be the best example of a pure C++ app that uses panda3d.
You can get pview.cxx from the full downloadable source distribution of panda or from part 1 of the 3 part distribution or you can cvs it from sourceforge. I recommend the full source distribution becasue it contains the “third party” libs that you’ll also need for this tutorial.
You’ll find pview.cxx in the main panda source path: “panda\src\testbed\pview.cxx”
3.) You should have the panda3d third party libs. You can get these from the full source distribution of panda or from part 2 of the 3 part distribution. I put these files in my panda installation directory as “C:\Panda3D-1.2.3\thirdparty”. I’m going to assume you did the same for the rest of this tutorial.
You should now have everything you need to get started.
a.) Launch VS 2003 and start a new project.
I made my project a standard win32 console application and started an “empty project”.
b.) Add pview.cxx to your project
I just copied it to my project folder and then added it to the project the usual way.
c.) Setup your path
You can do this in your project properties for each panda project:
For include files go to:
Project>Properties>C++>General>Additional Include Directories
and add: “C:\Panda3D-1.2.3\include”
For libs go to:
Project>Properties>Linker>General>Additional Library Directories
or if you’re lazy (I am) put it in your global VS environment path.
Go To: Tools>Options>Projects>VC++ Directories
add the above paths to your Include and Library Directories respectivly
d.)Link to the panda libraries:
libpanda.lib libpandaexpress.lib libframework.lib libdtool.lib libdtoolconfig.lib
e.) Compile & Run, you’re DONE !
Just kidding, you’re not done, but you should try it to see what happens. This is how far I got before things got tricky.
Note: I’m compiling in Debug mode by default. Everything below should also work for Release mode. I was able to do both.
Error #1 : Python Debug Library issues
"LINK : fatal error LNK1104: cannot open file 'python24_d.lib'"
Problem: Panda doesn’t come w/the debug lib for python. Neither does the regular python distribution. As far as I can tell you have to go compile all of python in debug mode for the privilege of debugging into python. Not something I cared to do.
Solution: Link agains the release version of Python instead of the debug version.
Go to: Project>Properties>Linker>Input and add “python24_d.lib” to your “Ignore Specific Library” section.
Then add “python24.lib” to your list of “Additional Dependencies”
Kiss your option of debugging into python good bye!
Error #2: Angry Linker
Linking... pview.obj : error LNK2001: unresolved external symbol "void * (__cdecl* global_operator_new)(unsigned int)" (?global_operator_new@@3P6APAXI@ZA) pview.obj : error LNK2001: unresolved external symbol "void (__cdecl* global_operator_delete)(void *)" (?global_operator_delete@@3P6AXPAX@ZA) pview.obj : error LNK2001: unresolved external symbol _gnu_optind pview.obj : error LNK2001: unresolved external symbol _gnu_optarg
Problem: Who knows (most likely internal panda stuff)
Solution: Add the preproccesor flag “WIN32_VC”
Go to: Project>Properties>C/C++/Preprocessor and add WIN32_VC to your list of preprocessor directives.
For me this line looks like: WIN32;_DEBUG;_CONSOLE;WIN32_VC
Error #3: Angry Linker Part 2
Linking... libcpd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) libcpd.lib(_tolower.obj) : error LNK2001: unresolved external symbol __malloc_dbg libcpd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
Problem: Panda apps need to be multithreaded
Solution: Go to: Project>Properties>C/C++>Code Generation and
change “Runtime Library” from “Single-threaded (/ML)” to “Multi-threaded DLL (/MD)”
e.) Compile & Run, you’re DONE FOR REAL!!!
No Really, you’re done. At this point you should have the basic pview app compiled and running in VS using only the libs that come w/the standard panda install and the third party libs provided on the panda site. You should now be able to use pview as a jumping off point for developing full c++ only panda apps using Visual Studio.