|
This guide describes the procedure for compiling Agar-based applications
(and the Agar library itself), under:
- Microsoft Visual Studio 2008
- Microsoft Visual Studio 2005
- Microsoft Visual Studio 2003
- Microsoft Visual Studio 2002
- Microsoft Visual Studio 6.0
It is assumed that you already have both the
Microsoft Windows SDK
("Platform SDK") and the
Visual C++ 2005 Redistributable Package
installed on your system.
|
About compilation options |
|
It is always preferable to use standard Agar builds (i.e., compiled with
FreeType, threads and OpenGL support) because they are more well-tested.
We provide package flavors such as nofreetype, nothreads,
but we don't recommend using these flavors under normal circumstances.
Unless you really need to, don't disable threads or OpenGL support in
Agar even if you are not using them directly in your application.
|
|
Get the latest Agar Windows binary package from the
download page.
You can unpack the archive to a location such as
C:\Program Files\Agar.
Start Visual Studio and bring up Tools / Options.
Select Projects and Solutions / VC++ Directories.
In the Show directories for field, select the option
Include files. If you have unpacked the Agar SDK package
into C:\Program Files\Agar, for example, insert the line:
C:\Program Files\Agar\include
Now select Show directories for / Library files and insert
the line:
C:\Program Files\Agar\lib
|
|
Agar (as of version 1.3) requires the SDL library. If you have not already
installed the SDL development package, go to the
SDL download area,
download the file SDL-devel-1.2.*-VC8.zip
(or SDL-devel-1.2.*-VC6.zip if you use Visual Studio 6.0),
unpack its contents into a location such as C:\Program Files\SDL
and add C:\Program Files\SDL\include to your include path and
C:\Program Files\SDL\lib to your library path like you just did
with the Agar SDK.
You will also want to copy SDL.dll to your C:\Windows\System
(or C:\Windows\System32 on Windows x64).
|
|
Optional / Recommended: Thread support |
|
If you have installed one of the nothreads flavors of the Agar SDK,
you can skip this section.
Thread safety and support for thread management in Agar-Core requires the
POSIX threads API.
POSIX threads are supported natively by all modern, decent operating
systems. Under Windows, you will need to use a small library called
Pthreads-win32.
Go to the Pthreads-win32
download area,
get the latest version (pthreads-w32-2-x-x-release.exe) and extract to
in some temporary location.
Rename and move the Pre-built.2 directory over to
C:\Program Files\Pthreads.
Copy the DLL files (or at least PthreadVC2.DLL) from the lib
subdirectory to your C:\Windows\System (or C:\Windows\SysWOW64
with Windows x64).
Go to
Tools / Options / Projects and Solutions / VC++ Directories
in Visual Studio and add
C:\Program Files\Pthreads\include to your include path and
C:\Program Files\Pthreads\lib to your library path like you
just did for Agar and SDL.
|
|
Optional / Recommended: FreeType font engine |
|
If you have installed one of the nofreetype flavors of the Agar SDK,
you can skip this section.
If FreeType if unavailable , Agar will revert to rendering text using a
built-in, monospace bitmap font.
You can download a binary package of FreeType for Windows, which was compiled
and tested using Visual Studio 2005, here:
FreeType235-win32-i386.zip,
and unpack it into a directory such as
C:\Program Files\FreeType.
If for some reason this package doesn't work, there is also a package
available from
GnuWin32 (SourceForge download area), but you will have to
rename lib/libfreetype.dll.a to freetype.lib (and
copy bin/freetype6.dll to your C:\windows\system also or
C:\windows\system32). You will probably get some linker warnings since
the GnuWin32 binaries were not compiled with Visual C++.
|
|
Optional: Installing FreeType (by compiling it yourself) |
If you would like to compile FreeType using Visual Studio yourself,
follow these steps:
Go to the
FreeType download area,
download the latest source package (ft*.zip), and unpack it to
some temporary location.
In the FreeType source directory, go to the builds\win32\visualc
subdirectory and open up freetype.sln in Visual Studio.
Locate the "Solution Configurations" selector in the Visual Studio toolbar,
and select "Release Multithreaded".
Now build the solution. This will generate the .lib file we need. Then,
right-click on the freetype project entry in Solution Explorer,
go to Properties and locate Configuration Properties / General.
In the Project Defaults section, set the Configuration Type
field to Dynamic Library (.dll), and build the solution again, this
time it will generate our .dll file.
Exit Visual Studio, and go to the build directory of FreeType
(i.e., objs in the FreeType source directory). Locate the
.lib file (e.g., freetype*MT.lib), copy it over to
a new directory, such as C:\Program Files\FreeType\lib, and
rename it freetype.lib. Then, locate freetype.dll in
release_mt in the FreeType build directory, and copy it to
C:\Program Files\FreeType\lib. You may want to copy this DLL
to your C:\Windows\System or C:\Windows\System32 as
well.
Copy the entire include directory from the FreeType sources to
C:\Program Files\Freetype\include.
Like you just did with Agar and SDL, add the directories
C:\Program Files\FreeType\include and
C:\Program Files\FreeType\include\freetype2
to your include path and add
C:\Program Files\FreeType\lib
to your library path in
Tools / Options / Project and Solutions / VC++ Directories.
You should now be able to use FreeType from Visual Studio.
|
|
Creating an Agar application in Visual Studio |
|
You can now create your application. In the Application Wizard,
set Application type to Console application, check
the Empty project box and click Finish.
In the Solution Explorer, go to Properties from the
popup menu of your project.
Click on Configuration Properties / Linker / System and set
the SubSystem parameter to
Windows (/SUBSYSTEM:WINDOWS).
Click on Configuration Properties / Linker / Input, and add
the following to the Additional Dependencies field:
ag_gui.lib
ag_core.lib
SDL.lib
SDLmain.lib
opengl32.lib
freetype.lib
If you are using a nogl flavor of the Agar SDK, you can remove
opengl32.lib.
If you are using a nofreetype flavor, you can remove
freetype.lib.
Add a new C++ file to Source Files in the Solution Explorer,
such as main.cpp. Here is a standard
Hello World
you can use.
Your application should now compile and run properly.
Note: If you want your application to be portable to other operating
systems and other development environments, consider the
BSDBuild
utility. It can even generate project files for you.
|
|
Compiling Agar itself with Visual Studio |
|
If you are not using the precompiled SDK and would like to compile Agar
yourself, look for the project files included in the .\ProjectFiles\
directory in the Agar source. Locate the .zip file matching your
Visual C++ release, for example vs2005-windows.zip will work with all
Visual C++ 2005 editions.
There are also some flavors such as nothreads, which disable thread
safety and nofreetype which does not depend on FreeType.
Unpack the archive into the very top Agar source directory, such that
Agar.sln will end up in the same directory as Agar's README
file.
Open Agar.sln with Visual Studio and you should now be able to compile
the toolkit.
Once Agar is compiled, run INSTALL-SDK.EXE in the root
of the Agar source directory to install the libraries on your system.
By default, they are installed into
C:\Program Files\Agar.
|
|
Generating custom Agar project files |
|
The set of project files included in Agar's .\ProjectFiles\ were
chosen for various common combinations of IDE versions, platforms and
compile-time options (such as nothreads). If you wish to use a
specific combination not available in .\ProjectFiles\, it is
possible to generate the project files with the following procedure:
- If you do not have Cygwin installed,
install it.
Make sure Interpreters / perl is enabled.
- Download PREMAKE.EXE from
here and
copy it to Cygwin's /usr/local/bin directory.
- Download BSDBuild,
install it with
./configure && make all install.
- Find Makefile.proj in Agar's top-level source directory,
open it up in a text editor.
- Add an entry to
PROJFILES, for example:
windows:arm:vs2005:-nogl:--without-gl
- Still in Agar's top-level source directory, execute
touch Makefile.config, then make proj from the Cygwin shell.
If successful, the new project files will appear under
.\ProjectFiles\.
- Unpack the project files in the root of the source.
|
|
If you are getting this linker error:
SDLmain.lib(SDL_win32_main.obj): error LNK2019:
unresolved external symbol _SDL_main referenced in function _main
Make sure your main() is declared exactly as int main(int argc, char *argv).
|
|