Posts

Build libexif for Windows and Visual Studio

This is a record of how to build / compile libexif (v0.6.21) binaries for windows. It is another entry in a Software Engineer’s daily ‘trial log’, however this time thanks to the excellent MinGW32 and the well written libexif things went rather well!

This readme says that you have 2 options, either hack together a project in Visual Studio to build the library or use MinGW32 to build it.

I tried the first option, but the main problem is that poor old Visual Studio can’t handle some of the more modern standard C (C99) constructs that libexif uses (e.g. the inline keyword).

So that left the MinGW route which is detailed here:

1.) Install MinGW32 onto your windows machine if you don’t already have it. Florian Wolters has a good description of how to do this here (thanks!).

I found it vital to put the path to WinGW32’s bin directory at the beginning of my system PATH variable, not at the end! Check that MinGW32 is working ok by trying Florian’s little test program.

2.) Get the libexif source here. Extract it to somewhere.

3.) Open a windows console window (CMD), don’t use GitBash or anything, just cmd.exe, cd into the extracted libexif folder. I used GitBash at the begining but was getting make errors, it turned out that some of GitBash’s tools were conflicting with MinGW’s tools.

4.) Make libexif by issuing the following commands:

Now during make, you may get an error like this:

libtool: link: cannot find the library `/home/keith/staged/mingw32/lib/libiconv.’

If this happens, go to your MinGW lib directory (e.g. C:\MinGW\lib) and delete this file:

libintl.la

And try running make again, if you continue to get the above error, then the advice out there us to delete any files with ‘keith’ in them, but luckily I didn’t have to.

If make & make install succeed, you should then see the install directories in /tmp, which you can access using MS explorer in your MinGW\msys directory:

e.g. maybe in C:\MinGW\msys\1.0\tmp

Thankfully that all worked for me, I was then able to link to the libexif libraries from a Visual Studio 2012 C++ project. The only gotcha I found is that when freeing the char* buffer allocated during a call to exif_data_save_data(), I found it important not to use free() but to use libexif’s own memory deallacator like this:

This is probably due to my test application using a different malloc() to the lib.

To link to libEXIF from visual studio you can directly add libexif.dll.a to Properties / Linker / Input / Additional Dependencies and then just make sure that libexif-12.dll is somewhere on the execution path.

If you don’t fancy all of this hassle the library binaries can be downloaded from here.

Handy archive of boost binaries for Windows / Visual Studio

Every now and again I have to work on an old software project that may use an older version of the boost libraries. Well if like me, you occasionally find that you are missing some boost .lib file or other binary then have a look at this very handy archive of the boost windows binaries maintained by Thomas Kent:

http://boost.teeks99.com/

Thanks Thomas, very handy!

boost_software_library

Compiling / Building libJpeg for Windows

Here is a record of how I managed to build libJpeg for Windows, Visual Studio 2012:

1.) Download & unzip the source, I downloaded it from here:

http://sourceforge.net/projects/libjpeg/files/latest/download?source=files

2.) Launch the Visual Studio Command console. To launch it, search for ‘command’ in the start menu, and you should see something like ‘Developer Command Prompt for VS2012’, start this.

3.) in the command prompt cd to the directory in which the libJpeg source resides

4.) At the command prompt, run the following commands:

In the first command make sure to replace the path with your path to your installation of the windows SDK, you may have to look around for this… If you get an error like this:

Then you haven’t correctly specified the SDK path.

When the compile finishes you should see libjpeg.lib in the top folder.

.

Building snappy compression library on windows with Visual Studio 2012

Snappy is a little fast software compression library by google. It eschews high compression rates for speed, it is very easy to use. Building it on windows for use with visual studio etc. is relatively straight-forward due to this github project by kmanley which provides it with a visual studio solution.

https://github.com/kmanley/snappy-msvc

To build the snappy static libraries, follow the instructions on the github page (README.rst).

If you get a build error like this:

Then copy the following code and place it at the top of the snappy.h header file (say, after #define UTIL_SNAPPY_SNAPPY_H__):

Once it has built, snappy.lib can be found in the Debug or Release folders, note that the debug build of the snappy lib is very slow so don’t do any tome testing with it! The release build screams along!

To use snappy in your C/C++ project you will need to #include “snappy.h” (which in-turn uses “snappy-stubs-public.h”) and also add snappy.lib to your project. Here is a little silly example:

If you get an error like this when you try to compile your client code:

Then it means you are trying to use the debug version of snappy.lib in a release build or vice versa, use the correct version and the error should go away….

Many thanks to kmanley!

The things a Software Engineer must sometimes do….

Today I am busy installing Windows XP (professional) and Visual Studio 6(!) onto a virtual machine, don’t ask…… I was sure I had seen the back of VB6…..

.

Create an SQLExpress database using Visual Studio

This took me a bit of time to figure out – how to create an empty SQL express database without using SQL Mangement Studio (I didn’t have it installed..) but instead using Visual Studio 2010 (and without having to add data sources, model definitions and other such muck into the context of a VS project)

 

Once you have a database you can use Visual Studio’s ‘Server Explorer’ pane to edit the DB and add tables etc. etc. but it isn’t obvious how to create an empty database in the first place, so in the end I did the following:

 

1.) Check that the SQL services are running – start them if necessary.

 

2.) Use Visual Studio to connect to the SQL Express master database – Choose the Tools / Connect to Database menu item. Specify ‘Microsoft SQL Server’ as the data source. Enter ./SQLEXPRESS as the ‘Server name’, or hit the browse button if you the have the browser service running. Leave the database name field blank. Press the OK button and VS should connect to the local master database, you should see it in the ‘Server Explorer’ pane.

 

3.) Now right click on the master database in the server explorer pane and choose the ‘New Query’ menu item. In the query window type:

 

 

Where DatabaseName is the name of the database that you want to create. Execute the query (press Ctrl – E) – this should create your new database.

 

3.) To connect to your new database repeat step 2.) and specify the database name – Visual Studio should now connect to it. Now you can add tables etc.

 

4.) You can now remove the connection to the master database in the Server Explorer pane if you like.

 

Visual Studio, TFS – Cheeps checking files out, There appears to be a discrepancy between the solution’s source control information about some project(s)

Over the last few hours I started seeing an annoying problem with Visual Studio and TFS on a geographically distributed software project that I am working on, Visual Studio kept on automatically checking out files that hadn’t been edited, I also started getting the following message before the files were automatically checked out:

 

“There appears to be a discrepancy between the solution’s source control information about some project(s) and the information in the project file(s).
Inbox”

 

After some investigation we figured out what the problem was – it was annoying problem, but in this case quite easy to fix.

 

When the TFS server was set-up originally we were all told to access it by its IP address over a partially set-up VPN. Now once the VPN was properly set-up, project contributors started to use the TFS server’s host-name instead of the IP address (as they should).

 

However, not all of the contributors were notified of the change and continued to use the IP address. Visual studio would update any files that had TFS info within them, checking them out and altering them to use either the TFS host name or IP address depending on the particulars of the local Visual Studio TFS set-up – hence all the trouble and all of the annoying error messages!

 

As soon as we changed from using the IP address to using the host name the problem went away.

 

It may well appear again however, as soon as someone else who uses the IP address instead of the host name checks in some files…

 

TFS is quite a good source control system but every now and again you can hear worrying echoes of its ignoble Visual Source Safe history and some of the hair-brained and crazy stuff that comes with it!

 

Visual Studio – Error The type or namespace name ‘CodedUITest’ could not be found

If you are trying to build some code with Visual Studio 2010 and get build errors like this:

 

The type or namespace name ‘CodedUITest’ could not be found …

 

Then it is probably because you are building with an edition of Visual Studio that is not Premium or Ultimate – the professional edition does not have the UI Test Tools built in.

 

If you are lucky you will be able to just remove the offending test project(s) with the broken references from the solution and build the rest – typically it will be only the test projects that won’t build.

 

To do this, choose the Build / Configuration manager… menu and un-check under the ‘Build’ column for any test projects that aren’t building.

 

Or shell out for an upgrade of Visual Studio!

 

Visual Studio 2010 Test – ‘The agent process was stopped while the test was running.’ wrecked my day!

Lots of software development time wasted yesterday due to a rubbish error and associated error message produced by the Visual Studio Unit test framework!

 

The agent process was stopped while the test was running.

 

No resolution as of yet – but I think it is due to a worker thread in a library that outlives the test’s existence… The problem doesn’t happen if I run the unit test as debug via the ‘Test / Debug / Run Tests in Current Context’ menu. Apparently, from my research it seems that this problem will also not happen in Visual Studio 2012, cold comfort indeed….

 

If I get it fixed Ill let you know…

 

Visual Studio 2010 – DLL Reference path won’t change when remove and re-add reference

On the whole Visual Studio is a great software development tool with a relatively low number of annoying bugs. However, there is one annoying bug that Microsoft doesn’t seem to be bothered enough to fix…

 

The problem happens if you remove and re-add a file reference to a DLL. When you re-add the reference (same file name in a different folder) by browsing to a different file location, Visual Studio will for some reason insist on using the previous file path to the DLL and not the new one!!!

 

You can find some more information about the problem here.

 

We were trying to change a reference’s path by removing and re-add it but it just didn’t work due to this bug!

 

So how can we get around this problem? Well one way is to change the reference path directly by editing the project file.

 

To do this, right click on the project in the solution explorer and choose ‘Unload Project.’ Once the project is unloaded, right-click on it again and then choose ‘Edit’, the project’s XML will be displayed in the editor.

 

Now search for references to the incorrect reference path and change it to your new path. To do this, look near the following elements:
[code lang=”xml”] and [/code]
and:
[code lang=”xml”] and [/code]

 

Finally, right-click on the project again and choose ‘Reload Project’ – check that the references are correct….

 

I hope this helps someone, it was the only way we could figure out how to get around the problem…