building an MSVC app with libpurple

Lee Roach phroggster at
Fri May 25 05:09:13 EDT 2007

David Byron wrote:
> dependency walker did the trick.  When I type glib-2.0.lib into MSVC (really
> Visual Studio 8) it ends up looking for glib-2.0.dll.  When I take it out
> altogether I get unresolved externs for things like _g_timeout_add and
> _g_main_loop_new.  I don't have a libglib-2.0-0.lib but I do have
> libglib-2.0-0.dll so I put that on the link line.  Unfortunately this in a
> dll that MSVC can't read.  MSVC fails to link with this error:
> ...\src\glib-2.12.11\bin\libglib-2.0-0.dll : fatal error LNK1107: invalid or
> corrupt file: cannot read at 0x2B8
> >From (the What is here,
> then? section), I would have thought this DLL was in the right format
> (although I may still get a mismatch with the MS C runtime libs but that's
> not what happening at the moment).
> Are there some tricks to convert libglib-2.0-0.dll into a format MSVC can
> use?
What you'll want to do in MSVC is specify your link path to 
"$PIDGIN_DEV_ROOT\win32-dev\gtk_2_0\lib" (plus others as needed) and 
specify "glib-2.0" (possibly "glib-2.0.lib") as the import lib. 
$PIDGIN_DEV_ROOT not being literal, but instead the same folder you've 
used to compile pidgin and libpurple out of. You should not need to 
rename any of the files extracted from Tor's zips or built by libpurple.

The thing Daniel hasn't mentioned, which I meant to reply to your first 
post on earlier but ran into more pressing problems, is that you'll need 
to make sure to inform your program on where to load load 
libglib-2.0-0.dll from. See pidgin/win32/winpidgin.c for an example of 
how to do it properly.

Simply query the registry at {hklm|hklu}\SOFTWARE\GTK\2.0\Path to 
determine the installed GTK runtime path, and SetDllDirectory (if 
available, otherwise SetCurrentDirectory) with that result plus "\\bin". 
Having never used nullclient, I'm not sure where that'll need to be 
added, but it'd have to be called before any code references functions 
that are exported by glib. In other words, before using init_libpurple() 
or any glib calls, make sure the OS knows where it and it's dependencies 
can be loaded from.

As far as conflicting C runtimes, I've noticed more the linker will 
complain but continue, and produce an executable that crashes immediately.
> I'm just trying to build a small test program that demonstrates I can mix
> toolchains.  Eventually the plan is to use libpurple as part of a bigger app
> that builds with MSVC.  Could we use mingw for everything?  Not sure, but
> the other guys I work with are Windows folks through and through and are
> basically demanding it.
I've successfully built a trivial program from scratch in Visual Studio 
2k5, that runs a couple test functions in Tor's provided Glib and a 
personally compiled libpurple, so it is in fact possible. Unfortunately, 
since it wasn't at all useful to my ultimate goals, it got deleted 
shortly after I got a MessageBox stating it got the expected results 
from libpurple and glib.


More information about the Devel mailing list