Install/Windows (Visual Studio)

From Agar

Jump to: navigation, search

This guide describes the procedure for compiling Agar 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 Microsoft Windows SDK] ("Platform SDK") and the Visual C++ 2005 "Redistributable Package" both installed on your system.

Contents

Installing Agar

Get the latest Agar Windows binary package from the Agar download page. Standard Agar builds (FreeType + threads + OpenGL support) are well-tested and preferred, but Agar can be compiled without FreeType ("nofreetype"), without threads ("nothreads") and without OpenGL support ("nogl"). Do not use these alternate flavors unless you really need to.

Unpack the package to its target 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 binary package into C:\Program Files\Agar, insert C:\Program Files\Agar\include in the list.

Select "Show directories" for / Library files and insert C:\Program Files\Agar\lib as well.

Optional: SDL support

The Agar-1.3 series previously required the SDL library. As of Agar-1.4, it is no longer a dependency. If you would like to use the existing "sdlgl" and "sdlfb" drivers, SDL must be installed. If you have not already installed the SDL development package, go to the SDL download area (http://libsdl.org/download-1.2.php), 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.

As you have just done with Agar, add C:\Program Files\SDL\include to your include path and C:\Program Files\SDL\lib to your library path.

You will also want to copy SDL.dll to 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 binary package, 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. Unfortunately, under Windows, you will need to install a small library called Pthreads-win32.

Go to the Pthreads-win32 download area, fetch the latest version (pthreads-w32-2-x-x-release.exe) and extract to in some temporary location. Move (and rename) 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.

Optional / Recommended: FreeType font engine

FreeType is the preferred font engine for Agar. Like Pthreads, it comes standard on most modern, decent operating systems, but under Windows, it needs to be installed manually.

If you have installed one of the "nofreetype" flavors of the Agar binary package, you can skip this section. If FreeType if unavailable, Agar will revert to rendering text using a built-in monospace bitmap font engine (ugly).

Installing FreeType from binary

You can download a binary package of FreeType for Windows, which was compiled and tested using Visual Studio 2005, here:

Unpack the archive 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 (see download area), but you'll need to rename lib/libfreetype.dll.a to freetype.lib, and copy bin/freetype6.dll to your C:\windows\system / C:\windows\system32). Expect some linker warnings since the GnuWin32 binaries were not compiled with Visual C++.

Compiling FreeType 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 / 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 can now 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 (unless using "nosdl" flavor)
  • SDLmain.lib (unless using "nosdl" flavor)
  • opengl32.lib (unless using "nogl" flavor)
  • freetype.lib (unless using "nofreetype" flavor)
  • pthreadVC2.lib (unless using "nothreads" flavor)

Add a new C++ file to Source Files in the Solution Explorer, such as main.cpp. Try the standard "Hello world":

#include <agar/core.h>
#include <agar/gui.h>
 
int
main(int argc, char *argv[])
{
	AG_Window *win;
 
	if (AG_InitCore("hello", 0) == -1 ||
	    AG_InitVideo(320, 240, 32, AG_VIDEO_RESIZABLE) == -1)
		return (1);
 
	win = AG_WindowNew(0);
	AG_LabelNew(win, 0, "Hello, world!");
	AG_WindowShow(win);
 
	AG_EventLoop();
	return (0);
}

Note: If you want your application to be portable to other operating systems and other development environments, consider the BSDBuild utility. Thanks to Premake, BSDBuild 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 flavors such as "nothreads" and "nofreetype" available, but do not use them unless encessary.

Unpack the archive into the very top Agar source directory.

Open Agar.sln with Visual Studio and compile. 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 project files

The set of project files included in Agar's .\ProjectFiles\ are automatically generated. These flavors were chosen for various common combinations of IDE versions, platforms and compile-time options (such as "--disable-threads" for "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:

  1. If you do not have Cygwin installed, install it (Download Cygwin). Make sure "Interpreters / perl" is enabled.
  2. Download PREMAKE.EXE from the Premake website and copy it to Cygwin's /usr/local/bin directory. Choose the last version of the 3.0 series (Premake 4 is not backward compatible and is not currently supported).
  3. Download BSDBuild from the BSDBuild website, install it with ./configure && make all install.
  4. Find Makefile.proj in Agar's top-level source directory, open it up in a text editor.
  5. Add your entries to PROJFILES, for example: windows:arm:vs2005:-nogl:--without-gl
  6. 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\.
  7. Unpack the project files in the root of the source.

Common issues

If you are getting a linker error similar to:

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).

If you are getting linker error similar to:

error LNK2019: unresolved external symbol: "__imp__timeGetTime@0" in Funktion "_Init".

Go to Solution Explorer, go to Properties from the popup menu of your project. Click on Configuration Properties / Linker / Input, and add the following to the Additional Dependencies field:

  • WINMM.LIB
Personal tools