-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation in default Cpp‐Project
To implement it you first should to make sure that you have what you need, if you want
additional debugging it would make sense to have the debug version in addition to the
release version of the library. The only thing that should change between these two is the
"InventoryLib.lib" file because it contains the code and link information for the header files
and the header files will be the same for both versions.
For this exemplary implementation in a C++ project I will use my testing application which I
used to test the functionalities of the library.
When implementing any library it's a good rule of thumb to create extra folders for includes.
In this case I would create a "ThirdParty" folder in the solution which then has a "Header", a
"Lib" and a "DLL" folder. If you don't use any DLLs like me you won't need that. These folders
are not needed but folder structure is always important when working in a production.
Once these folders are created put the two header files into the "Header" folder and the
"InventoryLib.lib" file into the "Lib" folder. If you have a multi-platform project you should
consider adding more folders to the "Lib" folder, first for the configuration like debug or
release and then for the platform, this way you can ensure the files are at the correct
location and it will help implementing the library in the next steps because we will make use
of property macros. In the end it should look somewhat like that:
To make this more clear, in this case the library project and the testing application project are
in the same solution, that's why the solution file is missing in this example, but we won't take
advantage over this fact and we will not add the library project as a dependency.
Now that the folders are setup we can open our project.
Before we start using the library we have to include it and tell the linker where to look for
our library. But before we add it we should add some custom macros for our third party
directories. For that click on the "View" and choose the "Property manager".
The Solution Explorer should vanish and instead you will see the
Property Manager. There you right-click on the project and choose
"Add New Project Property Sheet...", and choose a name, I chose
"ThirdParty". In this newly created property you can now add three
"User Macros".
Name | Value |
---|---|
ThirdPartyDir | $(ProjectDir)ThirdParty |
ThirdPartyLibDir | $(ThirdPartyDir)\Lib\$(Configuration)\$(Platform) |
ThirdPartyHeaderDir | $(ThirdPartyDir)\Header |
It should then look kind of like that:
After that we go back and open the solution explorer again to open the project properties. To do that open the property page of the project by right clicking it and clicking on "Properties". A new window should open and at the top in the drop down menus we want to choose "All Configurations" for our Configuration and "All Platforms" for our platforms. It should look something like that:
In here we have to add the includes and Linker inputs.
Property | Key | To Add |
---|---|---|
VC++ Directories | Include Directories | $(ThirdPartyHeaderDir) |
VC++ Directories | Library Directories | $(ThirdPartyLibDir) |
C/C++ -> General | Additional Include Directories | $(ThirdPartyHeaderDir) $(ThirdPartyLibDir) |
Linker -> General | Additional Library Directories | $(ThirdPartyLibDir) |
Linker -> Input | Additional Dependencies | $(ThirdPartyLibDir)\InventoryLib.lib |
As you can see in the last spot, it is important to declare the path and the file, otherwise it won't work.
Now the library is included and linked in the project and we can use it's header files "Inventory.h" and "BaseItem.h".