Configure PLplot for the Visual Studio IDE
CMake allows you to generate Visual Studio solution and project files.
As of version 2.8.2 of CMake, here are a few caveats:
- If you use Intel Fortran, the solution/project files may cause errors when building. These affect only the Fortran libraries and examples. It is due to a small bug in CMake that should be fixed with the next release.
- For some reason you can not run the examples directly. We have not found out yet what is the matter, but there is a workaround - see below.
Workaround for examples built with Visual Studio
- Build the PLplot libraries and examples via the ALL_BUILD project
- Open a DOS box in the Debug directory for any one of these examples
- Set the following environment variables:
set path=<build>\dll\Debug;%PATH% set PLPLOT_DRV_DIR=<build>\drivers set PLPLOT_LIB=<source>
where: <build> is the directory where PLplot was built and the directory "<source>\data" holds the .pal and .fnt files
- In this environment you can run the sample program
Walkthrough building PLPLot with Visual Studio
Having just been throught this process I thought I'd make sure it was available online for others. I've just compiled PLPLot 5.9.9 with wxWidgets 2.8 using Microsoft Visual Studio 2008 Express on a Windows 7 machine. It is a bit of an arduous process but it should work. My reason for wanting to do this is that I have wxWidgets compiled using Visual Studio in various differet configurations (with/without unicode, static/dynamic) and needed PLPlot with matching configurations and similar ease of changing proerties/recompiling. Here are the instructions. If you are not using wxWidgets then you can ignore the wxWidget specific instructions.
If you want to write GUI applications using wxWidgets then you probably already have a working sln file for compiling wxWidgets. If not then download one from wxPack - I found this the most reliable way to get a wxWidgets working on Windows. If you have just installed wxPack then navigate to the install folder and open the sln file. Now Go to Build->Batch Build, select all and build. I think some projects in the solution depend on others so it might take three or four attempts to get everything to compile. I never got the Universal configurations to compile, but don't use them so am not worried.
Now, to get antialiased graphics to work with wxWidgets you can use wxWidgets Built in antialiasing using the graphics context or you can use the AGG library. I seem to remember AGG was quite easy to build, so I'll leave that for you to work out. For Fonts again you have the option of wxWidgets internal or the FreeType library. Again you need to build FreeType if you want it.
If you want to use wxWidgets antialiasing you must recompile wxWidgets. In your wxWidgets directory find all instances of setup.h or setup0.h and set
#define wxUSE_GRAPHICS_CONTEXT 1
while I was at it I also set
#define wxUSE_POSTSCRIPT 1
This isn't needed for plplot but I thought as I was recompiling anyway I'd add it in.
Now right click the project core, and select properties. Under librarian->General->Additional dependancies or Linker->Input additional Dependancies add gdiplus.lib
Now go to Build->Batch Build and Build all. If you get errors about a manifest then go to Build-> Batch Build and ReBuild all. You may need to do repeated builds to get everything built as above. If you got the manifest error and rebuilt then do additional builds, not rebuilds until everything is built.
Download the PlPlot Source and unzip it. In this example I've chosen to unzip to D:\plplot-5.9.9. Make a new directory alongside this, I've chosen to call it D:\plplot-5.9.9_staticbuild.
Install Cmake if you don't already have it.
open a command prompt and enter
c:\program files\microsoft visual studio 9.0\common7\tools\vsvars32.bat
This may be different if you installed visual studio elsewhere, have a different version of visual studio or I guess the 32 may be a 64 on 64 bit machines.
Then
d:\ cd d:\plplot-5.9.9_staticbuild
Obviously modify this if you want to build somewhere else Now you can use Cmake to generate your visual studio solution/project files. The default command is
cmake d:/plplot-5.9.9 -G "Visual Studio 9 2008" -DPL_DOUBLE=ON -DBUILD_SHARED_LIBS=OFF
This will make your project files with plplot using double precision (in theory) to generate static libraries. There are some other options you might want to add, such as
-DENABLE_wxwidgets=ON -DHAVE_AGG=ON -DHAVE_FREETYPE=ON -DLIB_TAG="s"
These are pretty self explanitory. The DLIB_TAG option adds s to the end of the project files. I use this to indicate static. You can also set SHARED_LIBS to OFF to generate dynamic libraries but I haven't tried this yet.
After calling Cmake you should have a sln file in your directory and a config.h file with sensible settings. It might be worth checking your config.h file and your plconfig.h file. I had to uncomment the line
#define PL_DOUBLE
despite using the DPL_DOUBLE option
I had to do a bit of shuffling of code to get AGG and freetype to work. I had to copy the contents of my AGG include directory and the agg_font_freetype.h file from my agg folders to d:\plplot5.9.9_staticbuild\agg2
Now open the sln file if you haven't done so already. The projects you can see in the solution do all sorts of things it seems including copying libraries, reporting errors online and building the demos. The projects needed for building the libraries are
- plplot for the main C interface
- plplotcxx for the c++ interface
- plplotwxWidgets for the wxplplotstream and wxplplotwindow objects for use in wxWidget applications
- qsatime - don't know what this does
- csirocsa - don't know what this does either
I deleted all projects except for these ones to make life easier. You may want to include the examples or something. Instead of compiling these projects into 5 separate libraries I copied the source files from these projects into the plplot project to complile into one library. I didn't copy the plplotwxwidgets files accross because I don't intend to use these classes, but I presume you should be able to do so if you wish.
I had to make some changes to the code to make the library build. I had to add
#ifdef __cplusplus extern "C" { #endif
to the beginning and
#ifdef __cplusplus } #endif
to the end of csa.h and qsatime.h. You might also need to go through csa.c and add explicit typecasts to all calls to malloc.
Now you need to go through the project properties to ensure everything is as you want it, eg you are linking against the correct runtime library, the resulting libs are called the correct names and in a folder where you want them, etc.
I then went through a whole world of pain because whenever I tried to link one of my wxWidget projects to my new plplot library the code hung during wxWidgets initialisation. I don't know the exact cause but the problem is related to the wxwidgets_app.cpp file. I beleive this code allows console apps to generate gui style plots using wxwidgets. I don't need this functionality so the following terrible hack fixed the issue for me.
- Remove wxwidgets_app.cpp from the project.
- This will cause link errors due to missing definitions of wxPLplotFrame and wxPLGetApp().
- Go through wxwidgets.cpp and comment out all lines containing the above class/function. In some cases you may have to remove a whole try/catch block to do so.
- Build the library again.
I am now able to use plplot in my wxwidgets apps. I may have introduced a terrible bug, but providing the sections of code I hacked never get called I hope all should be fine.
You may want to create dlls as well as static libs. If so create a new folder called plplot-5.9.9_sharedlibs and start the process again from scratch using this folder. If you try to create a shared library solution in the same directory as the static library then your config files will be overwritten and your static build will stop working.