I’ve recently picked up TolonSpellCheckLib and Tolon NoteKeeper again after a long time away from it. I’m doing a lot of PL/SQL and testing at work at the moment, so I need to quench my thirst for C++ with a bit of ‘extra-curricular’ development.
Since last building my code in 2009 I have moved to Windows 7 64-bit and a new hard drive, so I was anticipating a fair bit of messing around in order to get a usable source/build tree again. As it turns out it wasn’t too bad, but I thought I would record a few useful notes on lessons I have learned from this process.
- Lesson 1 – Use Source Control
- Lesson 2 – Automate Your Build Process
- Lesson 3 – LINK : fatal error LNK1181: cannot open input file ‘link.obj’
- Lesson 4 – Compiler Warning Level 4 (/W4) is Your Friend
Lesson 1 – Use Source Control
I’ve been using Subversion for a while now and was mightily chuffed at the ease at which I was able to upgrade my old source trees to the new version of the svn client (1.6 to 1.7) in order to check whether I had any uncommitted changes lying about. Upgrading was a simple matter of running ‘svn upgrade’ at the root of the source tree (after taking a backup of course).
Without source control I would have been left manually comparing two old source trees with very little information to track down a problem if I got it wrong.
Lesson 2 – Automate Your Build Process
When I started experimenting with the enchant spell-checking library (see part 1 and part 2 of this escapade), I quickly realised that building it and all of its dependencies was going to get very complicated. I created a batch file that allows me to build this from scratch. To help stabilise my build I store compressed source versions of the dependencies in my source control repository as compressed files (any changes I need to make to these dependencies are managed by applying patches as part of my build process).
Having an automated build pays off almost immediately as it means you can build from scratch again and again knowing that the code is being compiled and linked in exactly the same way. When working with external libraries, this helps track down platform issues, build option issues and bugs.
So having got the latest code out of the repository onto my laptop, I simply ran ‘fullbuild.bat debug’ and the enchant library was very close to being successfully built at the first attempt. The only problem I encountered was the following lesson…
Lesson 3 – LINK : fatal error LNK1181: cannot open input file ‘link.obj’
If you get the above error whilst building using a makefile under Windows 7, do not panic. It seems that the environment variable handling is slightly different under Windows 7 so that when you come to the linking part of your traditional makefile, instead of calling:
LINK <link flags> <link objects>
the following is called
LINK LINK <link flags> <link objects>
The solution was to rename the LINK variable in the makefile to _LINK, so LINK = link
became _LINK = link
and all $(LINK)
references became $(_LINK)
. Thanks to NeilRashbrook on http://forums.mozillazine.org/viewtopic.php?t=470087.
Lesson 4 – Compiler Warning Level 4 (/W4) is Your Friend
There are some good warnings that only get output as this level in Visual C++ 2008, which makes it worth having switched on. My particular favourite is that it will tell you when you’ve accidentally performed an assignment instead of doing a comparison, i.e. if (x = 5)
rather than if (x == 5)
.
In my opinion it’s definitely worth switching this on and getting rid of all the spurious warnings in order to find these kinds of bugs. When I first compiled Tolon NoteKeeper with this option I got over 1200 warnings, most of which came from external libraries. For now I have assumed that a certain set of warnings in external libraries can be safely ignored, so I have selectively switched them off by using #pragma warning
as shown below.
#include "stdafx.h"
#include "NoteKeeper.h"
#include "NkpStructs.h"
#include "NoteKeeperDoc.h"
#pragma warning(push)
#pragma warning(disable:4244) // warning C4244: 'argument' : conversion from X to Y, possible loss of data
#pragma warning(disable:4996) //warning C4996: 'vsprintf': This function or variable may be unsafe. Consider using vsprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
#include "planydec.h"
#include "planybmp.h"
#include "plwinbmp.h"
#include "pljpegenc.h"
#include "plpngenc.h"
#include "pltiffenc.h"
#include "plbmpenc.h"
#pragma warning(pop)
#pragma warning(push)
#pragma warning(disable:4100) // warning C4100: unreferenced formal parameter
#pragma warning(disable:4189) // warning C4189: local variable is initialized but not referenced
#pragma warning(disable:4244) // warning C4244: 'argument' : conversion from X to Y, possible loss of data
#include "cryptopp/gzip.h"
#pragma warning(pop)
// etc...
EDIT: Build Script Files
You can now download some of the automated scripts I use for building my software. See http://www.tolon.co.uk/miscellaneous/lab/dependency-build-scripts/.
hi!
Nice work on notekeep and the deps, thanks π
Do you publish the patches for the deps somewhere? It would be nice if we could use them as well for other tools.
I publish all the patches+libs I use for php on windows in the php on windows download pages and begin to move them to a github’s org. Maybe we can share some work? π
@Pierre
Thanks! I’ve uploaded my scripts to http://www.tolon.co.uk/miscellaneous/lab/dependency-build-scripts/. I haven’t tested them in isolation from the NoteKeeper/TolonSpellCheck code yet as I’ve got some other work I need to do tonight.
re: sharing work: sounds like a good idea to me π Send me a link to what you’ve done already.
Hi,
I used to use visual c++,c# and all that, but I found it quite bloated. Asking the user to download lot the cnet framework and all that was a pain for a small application, which may be only 30k but needs 200mb of files installed just to run it. I have been using codeblocks as a replacement recently. However I haven’t done much programming for a while.
I had an idea for a new version of notekeeper. You run the exe and enter the username and password. It doesn’t save your data on your hard drive, but saves and loads by ftp. Thus you could be anywhere, on any computer and still get use your notes. I really wish notekeeper had this function. I have looked around at other note programs as well and none of them are as good as tolon notekeeper.
I am even on the point of writing my own, but I would prefer it if these features were added.
Thomas Williams
Thanks Thomas, but NoteKeeper is written in Visual C++ and not .Net, but I definitely agree that the massive size of some of the .Net redistributables has put me off from using it too. Fortunately Microsoft seems to have recognised that 231MB (.Net 3.5 SP1) was just way too big and have managed to reduce the .Net 4 redist down to 48MB, which is pretty impressive given all the classes it provides. The Visual C++ 2008 redist included with Tolon NoteKeeper is only 4MB.
I’ve thought about incorporating online storage into NoteKeeper before, but I really need to redesign the storage code before I do that. The first step will be to move away from my own custom file forwards and instead use a more reliable one such as SQLite; once that’s done, supporting online storage shouldn’t be too much of a big step.
I hope you can stick with NoteKeeper a little longer whilst I get back into working on it!