Agar Logo

   <-- Back to Documentation

Installing on Windows XP and earlier (Visual Studio build) - LibAgar

This is a step-by-step guide for compiling Agar applications under the Visual Studio IDE from Microsoft.

An alternate build method for building Agar on Windows (using MSYS2) is described at: Installing on Windows with MSYS2.

Prerequisites
General Visual Studio Issues

How to add Include & Library paths

Using external libraries from Visual Studio requires that the explicit Include and Library paths be specified. In Visual Studio versions prior to 2010, you can add a directory to the Include or Library path from Tools / Options, then Projects and Solutions / VC++ Directories. In the "Show directories for" field, select the option "Include files" or "Library files" and add the new directory path to this list.

Starting from Visual Studio 2010, Library/Includes paths are handled differently. The Projects and Solutions / VC++ Directories dialog is no longer available, and Library/Include paths can be set on a per-project basis (i.e., right-click on the project node and select Properties / VC++ Directories). See this article for details.

It is still possible to specify global Include/Library paths by manually editing the Microsoft.Cpp.*.user.props files (found under AppData\Microsoft\MSBuild\v4.0 relative to your Local Settings\ or C:\Users\%USERNAME%\). Open this file in a text editor, and append your directories to $(IncludePath) and $(LibraryPath) like so:

    <PropertyGroup>
      <IncludePath>$(IncludePath);C:\Program Files\Agar\include\x86</IncludePath>
      <LibraryPath>$(LibraryPath);C:\Program Files\Agar\lib\x86</LibraryPath>
    </PropertyGroup>
  

For the x64 version:

    <PropertyGroup>
      <IncludePath>$(IncludePath);C:\Program Files\Agar\include\x64</IncludePath>
      <LibraryPath>$(LibraryPath);C:\Program Files\Agar\lib\x64</LibraryPath>
    </PropertyGroup>
  

Disable parallel compilation in Visual Studio 2010

Parallel building may trigger in bugs in Visual Studio 2010. If you are getting random build errors (e.g., some files cannot be opened even though they exist), make sure to disable parallel builds. To disable parallel builds, go to Tools / Options / Project and Solutions / Build and Run, and set "maximum number of parallel project builds" to "1".

Installing Agar
  1. Download the latest Agar binary package and unpack it to its target location such as C:\Program Files\Agar.
  2. 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".
  3. Assuming you have unpacked the Agar binary package into C:\Program Files\Agar, add C:\Program Files\Agar\include\x86 (or C:\Program Files\Agar\include\x64 and C:\Program Files\Agar\lib\x86 (or C:\Program Files\Agar\lib\x64) to your VS Include/Library Paths.
Optional: SDL 1.2 support

SDL 1.2 enables support for Agar's sdlfb & sdlgl drivers.

  1. Download the SDL-devel-1.*-VC.zip package from the SDL 1.2 Download Area.
  2. Add C:\Program Files\SDL\include and and C:\Program Files\SDL\lib\x86 (or C:\Program Files\SDL\lib\x64) to your VS Include/Library Paths.
  3. Copy x86\SDL.dll to C:\Windows\System (or C:\Windows\System32 on x64), and x64\SDL.dll to C:\Windows\SysWOW64.
Optional: Thread safety

While Agar itself does not rely on threads for its own operation, it can be compiled such that all of its public functions become free-threaded. This requires the Pthreads-win32 library to be installed.

  1. Go to the Pthreads-win32 download area, fetch the latest version (pthreads-w32-2-x-x-release.zip) and extract to in some temporary location. Move (and rename) the Pre-built.2 directory over to C:\Program Files\Pthreads.
  2. Copy the contents of the dll\x86 directory to your C:\Windows\System (or C:\Windows\System32 on x64), and the contents of dll\x64 to your C:\Windows\SysWOW64.
  3. Add C:\Program Files\Pthreads\include and C:\Program Files\Pthreads\lib\x86 (or C:\Program Files\Pthreads\lib\x64) to your VS Include/Library Paths.
Optional: FreeType

FreeType is the preferred font engine for Agar. FreeType provides Visual Studio project files so its build process is simple.

  1. Go to the FreeType2 download area, download the latest source package (ft*.zip), and unpack it to some temporary location.
  2. In the FreeType sources, go to the builds\win32\vc* directory for your version of Visual Studio and open freetype.sln. Locate the Solution Configurations combo box in the Visual Studio toolbar, and select "Release Multithreaded".
  3. Now build the solution. This will generate the static .lib file. 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 to generate the .dll version.
  4. Exit Visual Studio, and go to the build directory (e.g., \objs\win32\vc2010). Locate the .lib and .dll files and install them into your C:\Program Files\FreeType\lib\x86 (or C:\Program Files\FreeType\lib\x64), renaming them to freetype.lib and freetype.dll.
  5. (Optional) Copy freetype.dll to your C:\Windows\System (or C:\Windows\System32 on x64) to make it available system-wide.
  6. Copy the entire include directory from the FreeType sources to C:\Program Files\Freetype\include.
  7. Add C:\Program Files\FreeType\include and C:\Program Files\FreeType\include\freetype2 to your Include Paths.
  8. Add C:\Program Files\FreeType\lib\x86 (or C:\Program Files\FreeType\lib\x64) to your Library Paths.
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
  • winmm.lib
  • opengl32.lib (if OpenGL is enabled)
  • SDL.lib (if SDL is enabled)
  • SDLmain.lib (if SDL is enabled)
  • freetype.lib (if FreeType is enabled)
  • pthreadVC2.lib (if multithreading is enabled)

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(NULL, 0) == -1 ||
              AG_InitGraphics(0) == -1) {
		return (1);
	  }
          win = AG_WindowNew(0);
          AG_LabelNew(win, 0, "Hello, world!");
          AG_WindowShow(win);
          AG_EventLoop();
          return (0);
  }
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 .zip source distribution. Locate the .zip file matching your Visual C++ release, for example vs2005-windows.zip will work with Visual C++ 2005 editions and later.

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 compilation profiles (advanced)

The set of project files included in Agar's .\ProjectFiles\ are automatically generated. These flavors were chosen for various popular combinations of IDE versions and platforms. The build may be configured using options (i.e., --disable-threads will disable multithreading support). If you wish to use a compilation profile not already available in .\ProjectFiles\, follow this procedure:

  1. If you do not have Cygwin installed, install it (Download Cygwin). Make sure "Interpreters / perl" is enabled.
  2. Download the precompiled Premake 3.7 binary (premake-win32-3.7.zip) and copy it to Cygwin's /usr/local/bin directory.
  3. Download the latest stable release of BSDBuild and 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. Add your entries to PROJFILES (see the commented-out example profiles at the bottom of Makefile.proj).
  5. While 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\.
  6. Unpack the project files in the root of your Agar source directory.
Troubleshooting

1) If you've compiled with SDL support and are getting a linker error similar to:

  SDLmain.lib(SDL_win32_main.obj): error LNK2019: unresolved external symbol
  _SDL_main referenced in function _main

Then make sure SDL.h is included in your file with main() and that main() is declared exactly as follows:

  int main(int argc, char *argv)

2) If you are getting linker errors such as:

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

Then your "Linker / Input" settings are probably missing a library (in this example, winmm.lib is missing). The linker input settings are accessible from Solution Explorer, then "Properties" from the popup menu of your project. Click on Configuration Properties / Linker / Input, and add the missing libraries to the Additional Dependencies field. See the Creating an Agar application in Visual Studio section above for details.


3) If your program is not starting due to missing MSVCR100.DLL, make sure that the Visual C++ 2010 Redistributable Package is installed on your system. Any application compiled with Visual Studio depends on this library (if you don't like this, consider using MinGW instead of Visual Studio). Developers usually bundle a copy of the file with their application, or link statically against it (you can link statically by selecting the "Multi-threaded (/MT)" option under "C/C++ -> Code Generation").


4) If your program fails to start and Visual Studio is not reporting any useful information, make sure that all dependencies are compiled for the same architecture. As a last resort, try recompiling all libraries (pthreads, freetype, etc.) yourself.


5) If you are using Agar's wgl driver (the default on Windows) and your application freezes a few seconds after focus is switched to a different application, this is an Aero bug affecting OpenGL applications. To disable Aero, right-click on the Windows Desktop, click on Personalize, and select a basic theme such as "Windows Classic". Alternatively, you can work around this problem using a compatibility tweak: right-click on your application .exe file, go to Properties / Compatibility, and check the "Disable visual themes" option.


Csoft.net ElectronTubeStore