Previous Topic

Next Topic

Book Contents

Book Index

How to create your own library

This subject describes how you can create your own libraries and reuse them with greatest ease from project to project.

In This Section

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

See Also

Appendix

Step by step

Websites and other references

Previous Topic

Next Topic

Book Contents

Book Index

The general directory structure and logic for your own libraries

The main idea is to make it as easy as possible to create, maintain and use your own libraries. This implies a certain structure.

Below you see a suggested directory structure:

The important sub directory structure is from Common and below. Below Common you'll find Classes and Routines. Those two directories contain the class-based libraries and the procedural routines respectively. You see a sample class library with the name of Sample Library below Classes.

The grand idea here is that each library project is set up to move the result of the project, the header and library files, to the include and lib directories respectively. Since Visual Studio needs to know where to search for both include- and library files in it's global options dialog for directories, it is fairly easy to specify just one extra include directory (here it will be D:\Projects\Private\Common\Include) and one library directory (D:\Projects\Private\Common\Lib).

The header file will contain the commands that automatically enables the compiler to pick the correct library file (release or debug!).

See Also

How to create your own library

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

Create a new project

Ensure you select Win32 Static Library as project type

See Also

How to create your own library

The general directory structure and logic for your own libraries

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

Select features of library

The settings here are very important!!! Bear in mind that all components involved in an application needs the same compiler- and link settings. So, if your main application (the one that will use this common shared library) use MFC, so should you, even if this library doesn't do a thing with MFC. This is important!

The support for pre-compiled headers speed up the build process, but fill up your hard disk. I tend to run it on, if the main applications has it turned on. You don't want different settings!

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

You're ready to create the library

Press Ok and you're ready to build the project workspace.

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

You now have an empty project workspace

The StdAfx.h and StdAfx.cpp are system generated files, for the pre compiled header support in the previous steps.

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

Set the very important common settings for all Notes API applications

This step is important so you keep the settings of the main project and your library the same.

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Previous Topic

Next Topic

Book Contents

Book Index

Tell the linker to move the result (the library file) to the common lib-directory

In order to get our global directory logic to work, we need to overwrite the default suggestion in the Output file name field. Change the directory path to the following:

..\Lib\

This ensures that the linker put the result of this build in the common Lib directory as shown in the directory structure above!

The next point is to ensure that the debug-build has a suffix D to it's library name. In the sample above, the debug-build library name is:

Sample LibraryD.lib

Why ? Because the release build will only have the name, Samle Library.lib (No D!).

Remember that you easily switch to the release build settings by changing the Settings For field.

Start using the library by including the header file

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Since we have a debug- and release build of our library (Sample LibraryD.lib and Sample Library.lib respectively), we need to somehow tell the compiler what version to use. The absolutely best way to do this, is by the use of pragma (compiler directives, or commands). Somewhere in your header file, include this couple of lines:

#ifdef _DEBUG
#pragma comment(lib, "Sample LibraryD.lib")
#else
#pragma comment(lib, "Sample Library.lib")
#endif

If you read the above lines carefully, it should interpret to something like this; "If we are building a debug-build, then use the Sample LibraryD.lib, otherwise use the Sample Library.lib".

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

Previous Topic

Next Topic

Book Contents

Book Index

Tell the build-process to copy the header file(s) to the common include-directory

By entering this DOS-command you ensure that the header file of the library is placed in the common Include-directory specified above.

Tell the build-process to copy the header file(s) to the common include-directory

Start using the library by including the header file

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Start using the library by including the header file

Previous Topic

Next Topic

Book Contents

Book Index

Start using the library by including the header file

Somewhere in the main application (the one that use this library), you will typically find something like:

#include <Sample Library.h>

Since we use the angel-brackets, you tell the compiler to use the so-called system include directories, which we have specified in the global directories! And, since we placed the header file above in the common Include-directory, Visual Studio will find the file. And - finally due to the pragma directives, the linker knows which library, either debug- or release, to use, completely automatically!

Beautiful!

See Also

How to create your own library

The general directory structure and logic for your own libraries

Create a new project

Select features of library

You're ready to create the library

You now have an empty project workspace

Set the very important common settings for all Notes API applications

Tell the linker to move the result (the library file) to the common lib-directory

In the header file, add these compiler-commands (aka "pragma directives") - they'll guide the compiler to the correct libs later.

Tell the build-process to copy the header file(s) to the common include-directory