Googles appar
Huvudmeny

Post a Comment On: cbloom rants

"07-15-12 - libpng DLL Delay Load"

11 Comments -

1 – 11 of 11
Blogger Mārtiņš Možeiko said...

If you are using Visual Studio, then it can do all this automatically. Check out "Project Settings -> Linker -> Input -> Delay Loaded Dlls" setting. Then dll file will be referenced from application, but it won't be loaded until somebody actuall tries to call function from it.

July 15, 2012 at 4:46 PM

Blogger cbloom said...

Holy crap. LOL.

July 15, 2012 at 5:52 PM

Blogger Carsten Orthbandt said...

You can get libpng to support static linkage. Let me know if you want the gory details.

July 16, 2012 at 10:49 AM

Anonymous Anonymous said...

I used to do the #include "foo.inc" for lists of things and include it multiple times, but I've swung around to instead doing

#define ITEMS item(whatever1) item(whatever2) item(whatever3) ...

With each item on one line and backslashes between them. This seems a bit less aggressively obfuscated.

July 16, 2012 at 4:14 PM

Blogger cbloom said...

Oh yeah, I actually switched to that method myself a while ago, but then forgot about it and switched back to the multi-include. You're right that it feels cleaner somehow.

July 16, 2012 at 4:41 PM

Blogger cbloom said...

@Carsten - sure, share the knowledge; you can email me or post it.

I do hope that everyone realizes by now that DLL's are a total disaster and you should statically link everything you can. Dlls are an annoyance for the client and a failure mode for your app. Remove failure modes whenever possible. Robustinate!

July 20, 2012 at 9:59 AM

Blogger Fabian 'ryg' Giesen said...

Interestingly, the main way a lot of people use DLLs is not to factor out common code (as is the intention), but merely to split compilation into several chunks that each have acceptable link times.

Once you start thinking about this, it immediately becomes clear how unbelievably broken this is - linking is getting too slow, so now we do it every time the process is launched?

Of course the key is that a) there's no dead stripping across module (app/DLL) boundaries, and b) DLLs only contain symbols that you intentionally export, not tons of autogenerated name mangled gunk that happens to be publicly visible even though there's no good reason for it.

I'd really like a notion of "packages" with DLL characteristics (all internal dependencies resolved, LTCG "island", own scope, only explicitly marked symbols visible from the outside), but still used for static not dynamic linking. Of course that requires innovation in linkers, something that doesn't seem to have happened in over 20 years.

July 22, 2012 at 5:31 PM

Blogger cbloom said...

@Unknown - totally.

It's one of those things for my list of "what the C standards committee would do if they were actually programmers".

Perhaps the #1 problem with C is that sharing work between disparate projects is a total disaster.

Packages would be at least a step in the right direction. It would isolate things like "hey I assume a certain override for operator new" which are part of what make sharing C such a clusterfuck.

July 23, 2012 at 5:29 PM

Blogger Carsten Orthbandt said...

We don't use a stand-alone static lib of libpng. Instead we included the required source code in our core lib.

The files you actually need are:
png.c/.h
pngconf.h
pngerror.c
pngget.c
pngmem.c
pngpread.c
pngpriv.h
pngrio.c
pngrtran.c
pngrutil.c
pngset.c
pngtrans.c
pngwio.c
pngwrite.c
pngwtran.c
pngwutil.c

We removed the zLib from libpng and used the one we have already. That requires a change of the zlib include path on png.h (line 397 im my version).

We also changed all the PNG_EXPORT function decls to "extern" to make C++ happy.

And we had to disable PCH on the libpng .c files of course.

That's pretty much it.

July 24, 2012 at 11:46 AM

Blogger Carsten Orthbandt said...

Oh, and I wholeheartedly agree on the DLL rant. Major PITA with no gain whatsoever.

July 24, 2012 at 11:50 AM

Blogger ryg said...

Or you could, you know, use stb_image. (That "Unknown" above was me by the way, apparently Blogger doesn't understand Google's multiple sign-on stuff that I need to do to access both my private and work GMail account. Sigh.)

July 24, 2012 at 11:30 PM

You can use some HTML tags, such as <b>, <i>, <a>

This blog does not allow anonymous comments.

Comment moderation has been enabled. All comments must be approved by the blog author.

You will be asked to sign in after submitting your comment.