Building Anti-Grain Geometry for the AggOO library
Note: The latest cvs will have AGG included in the project, making the following notes unnecessary. The next release of AggOO will also start including AGG, which makes building easier. If you are using AggOO 0.1.5 or earlier, you may need to look over this information. AggOO after 0.1.5 may disregard this tutorial.
Building Anti-Grain Geometry for the AggOO library
Before building and using the AggOO library, the Anti-Grain Geometry library must be available on your system. This isn't a straight-away installation, but it shouldn't be too difficult.
Download Anti-Grain Geometry
Head over to http://www.antigrain.com and download the appropriate archive for your platform. Currently, AggOO uses AGG 2.4, but later versions will probably work if the build instructions are followed. The only major differences between AGG 2.4 and 2.5 is the license changed from Modified BSD license to the GPL license. AggOO will remain under the Modified BSD license (libraries should not dictate the license of the application!,) which is compatible with the GPL.
Prepare the library
AGG comes with an example which can display SVG files. Although this is actually an incomplete loader, it does a pretty decent job, and is already integrated. AggOO will use parts of this (along with some customized classes) for loading SVG files. (AggOO also supports .AI files internally.) However, AGG has all of the SVG handling files located in examples/svg_viewer. This isn't a very nice path for a production library, so these files need to be moved. I have them located in include/svg and src/svg (for the header and implementation files, respectively.) This is how the AggOO source files expect them to be, so if you'd rather use a different path, you will need to make some changes to the AggOO source…
Building the library
I have built AGG using Visual C++ .NET (2002) and 2005. I have also used Code::Blocks on both Windows and Linux. Other IDEs should work similarly.
Build for Windows
The documentation for AGG suggests dropping the necessary files into your projects when using it under Windows. This can allow you to streamline your projects by keeping the unnecessary stuff out, but I prefer to build as a library that can be linked to the project rather than having to sort out which additional files need to be added to my project. Ideally, I would like to build AGG as a DLL which could be linked dynamically to AggOO (and other projects) so that a change to the AGG library wouldn't require rebuilding everything else in order take advantage of those changes. However, I don't think its a good idea for me to mess with the AGG files, so we'll just build them as static libraries. I have not put much time and effort into trying to build AggOO as a DLL, so I won't cover building AGG for DLLs yet.
Once the archive is downloaded, decompress it somewhere convenient for you. For this tutorial, I'll use the directory c:\SDKs\agg\agg-2.4\, but you can use whatever you like. Add the include directory (c:\SDKs\agg\agg-2.4\include\) to your compiler's search path. Also, create a new directory for the library files (c:\SDKs\agg\agg-2.4\lib\) and add this to the linker's search path (your new library will be moved here, and future projects will look here when linking.) I also created a scripts folder where I save the project files, but that's entirely up to you.
Start a new Static Library project
In your IDE, start a new project to make a static library named agg. You should be able to accept the defaults all the way through. Before we get too far, create another static library project named 'agg_main' and add this to the current solution/workspace/whatever. This will be for the platform dependent code used for the demo applications.
Add files to the projects
Add all of the *.cpp files in c:\SDKs\agg\agg-2.4\src\ to the agg project. Also, add all of the header files in c:\SDKs\agg\agg-2.4\include to the agg project (this isn't really necessary, but I like having them in the project.) Add the header files located in c:\SDKs\agg\agg-2.4\include\util\ to the agg project as well.
Add everything in the c:\SDKs\agg\agg-2.4\include\ctrl\, c:\SDKs\agg\agg-2.4\include\platform\ and c:\SDKs\agg\agg-2.4\include\platform\win32 directories as well as the c:\SDKs\agg\agg-2.4\src\ctrl\ and c:\SDKs\agg\agg-2.4\src\platform\win32\ directories to the agg_main project.
After the projects have built, you could manually copy and rename the library files, but I like to make the IDE do that for me. In Visual C++, open the project properties (right-click the project, then choose 'Properties') and select 'Build Events→Post-Build Event.' Under 'command line,' enter the following code for the debug configuration: move “$(OutDir)\$(ProjectName).lib” “c:\SDKs\AGG\agg-2.4\lib\agg_d.lib”, and for the release: move “$(OutDir)\$(ProjectName).lib” “c:\SDKs\AGG\agg-2.4\lib\agg.lib”. Note that this will make the library files agg.lib and agg_d.lib. Be sure to conform to this if you are copying the files yourself (or else change the AggOO settings.) Similarly, the files for agg_main should be agg_main.lib and agg_main_d.lib.
To automatically copy the files in Code::Blocks, right-click the project and select “Build Options.” Select the “commands” tab, and enter mv “libagg.a” “c:\SDKs\AGG\agg-2.4\lib\libagg_d.a” for the debug build, and mv “libagg.a” “c:\SDKs\AGG\agg-2.4\lib\libagg.a” for the release build. Notice that I am using the gcc compiler, hence the ”.a” extension. You may need to make modifications based on you environment. The agg_main project should move the files to the same location, naming them “libagg_main_d.a” and “libagg_main.a.”
At this point, you should be able to build the entire solution (Build→Batch Build…, build everything) and be set.
I won't cover the AGG demos, but basically, there is already a project file you can import and build.
Build for Linux
NOTE: This was tested on Ubuntu. Other distributions may vary.
The Linux versions of the Anti-Grain archive uses makefiles to build a static library. You can use this to simply type “make” to build the library. On the other hand, you can also use Code::Blocks for Linux to follow the same route described for Windows above. I chose to do this, and created the debug and release libraries, in the same manner as under windows (I find it easier.) Just make sure to replace the win32 platform files with those for your target platform (I'm using X11.)
Common Mistakes (for me, anyway)
For some reason, I sometimes forget to check the code generation option. It is important that all projects that are used together have this setting the same. For example, if the library is built with Multi-Threaded DLL, then the application should use this setting as well. This is important, but easy to forget.
- Login to post comments