Allegro
Creating a Project That Uses the Allegro Library
In Microsoft Visual Studio 2015/2013 select File -> New Project from the menu. This will open a dialog window for creating a new project. In the left pane select Visual C++, and in the right pane select Empty Project.
Type in the name of the project below (for example AllegroProject) and then click the OK button.
This will create a new empty project.
In the Solution Explorer window, right-click on Source Files, then select Add -> New Item. This will open a dialog box for adding a new file to the project. Select C++ file (.cpp), and then type main as the name of the file. Click the Add button. This will add a source code file to the project.
Now, we need to specify where the header
files of Allegro library are located. We know that they are in the directory c:\allegro\include
, but our project in the IDE is missing that piece of information.
In the Solution Explorer window,
right-click
on the name of the project
(i.e. AllegroProject),
then select Properties on the bottom. A Property Pages dialog window will appear. In the Configuration drop-down list (it is on the top)
select All Configurations. In the pane on the
left, select Configuration Properties, then VC++ Directories. In the pane on the right, select
the row Include Directories, and, on the far
right of that row, click on the
drop-down button, then select Edit. A dialog box will open having 4 buttons on the
top. Click on the first button having an icon of the yellow folder on it. On a
line that appears type
c:\allegro\include
Click OK, and then click OK again.
That adds the path to Allegro library
header files into our project. The next thing we must add to the project is the
Allegro library code. The Allegro library for Microsoft
Visual C++ has already been compiled, so its object code is in the
library object file, having the extension .lib
[*].
In the Solution Explorer window,
right-click on the name of
the project (i.e. AllegroProject), then select
Add -> Existing Item. In the File name box on the bottom, type:
c:\allegro\lib\allegro-4.4.2-md.lib
This is not quite true. This would be the case if we were to statically link with the Allegro library, but we are actually going to link dynamically with it. In this case, the library is compiled into a .dll
file which will be loaded by a proxy in a .lib
file. You have already copied the .dll
file to the windows\system32
directory after you downloaded the Allegro library. However, you do still need to link with a proxy static library (.lib
) file that will load and call functions from the mentioned dynamic link library (.dll
) file. Similarly, on a Linux-class OS, object files have the extension '.o', static libraries have the extension '.a', and dynamic link libraries have the extension '.so' (for: shared object file). A difference is that a dynamic link library does not need a proxy static library, like it does on Microsoft Windows OSes.
That will make the compiler link the program with the specified library file.