Shared String Library
An implementation of shared strings in C++.
David C. Haley (david at the-haleys dot com)
Instructions for Unix and Windows environments. Assumes that you have access to:
In the directory -build_unix- there is a Makefile to build both the library and the test files. It should be sufficient to type:
This will compile everything and put the library into -lib- and the test program into -bin-. If you -make clean- after installing, it will clean up the compiled files but will not uninstall the library and test program.
Note: The ‘make install’ isn’t what you might expect from a make install. Normally such a process would put the library into e.g. -/usr/local/lib-. But since the majority of target users of this library will not have root access, I made the install process go to a more convenient location.
In the directory -build_win32- you will find a Visual Studio 7 project file. You should be able to open that and select ‘Build | Build Solution’ to compile the library. This will create files ‘sharedstr_win32.lib’ and ‘test-sharedstr.exe’ in the -debug- subdirectory of -build_win32-. You should then copy the library wherever you want e.g. into the -lib- directory.
Covers usage and linking of the library.
Using the library in your program
Using the library is fairly simple. The basic idea behind the library is that shared string templates are defined using a manager wrapper, and then you use this template definition as your shared string. There is very little for you to do: you only need to call a macro before -typedef-’ing the shared string.
// (in a .h file somewhere)
// (in a .cpp file somewhere)
// (at the global scope)
Linking the library into your project
Consult your compiler’s documentation for more detailed information on how to do this. Here are some brief instructions, but for examples you can look at the makefile or project file for the test code.
At the link phase of your compilation, add the following;
where [dir] is wherever you put the shared string library. The -L command tells g++ where to find the library, and -lsharedstr tells g++ to add the sharedstr library (libsharedstr.a).
Under the project properties, go to the link step and add the library you compiled to the ‘input’ box. Also make sure that the directory it’s in is on the library input path: you can do this in the link step as well, or set it to your global Visual Studio settings under ‘Tools | Options | Projects | VC++ Directories | Library Files’.
To do ... For a preview, go through this forum post; http://www.gammon.com.au- /forum- /bbshowpost.php?bbsubject_id=5237 That’s where the project was born and initially discussed. Maybe some of the reasons for my choices will become clear there, but probably not... :-)