|
|
||
Kohsuke Kawaguchi's Blog
«Introducing Winp: Windows Process Manipulation Library |
Main
| Fast-open IntelliJ plugin updated »
Tips on creating a small JNI jar on WindowsPosted by kohsuke on March 19, 2008 at 11:25 AM | Comments (2)I created a small library to manipulate Windows processes the other day, and someone showed interest in how to create a small footprint DLL in Windows. So this blog is to explain you what I did. The main idea behind cutting down the size of DLL is to avoid linking the Visual C++ runtime. In many cases, you'd only use JNI to talk to other DLLs (most often to kernel32.dll or ntdll.dll — IOW, system calls), and in those situations, this is quite feasible. For this to work, you'll do the following:
That's it. If the linker runs successfully, you should see a substantially smaller DLL. When you accidentally end up using functions from the C runtime library, the linker often fails with an error saying "unresolved symbol: _main". When that happens, you need to turn on the /VERBOSE linker option and see which dependency is causing the C runtime to kick in. Kernel does offer the basic string manipulation libraries, so those are useful when you don't have the C runtime. Ditto for memory allocation functions, but those are often somewhat awkward. I've also read somewhere that you can pack the PE header by using the smaller alignment, but I couldn't figure out how to convince the linker to do that, or whether that is really legal or not. In conclusion, if you are using the C runtime, then you should seriously question if some 20KB improvement in the footprint is worth your productivity drop, but if you are not using the C runtime, these relatively mechanical steps would give you the satisfaction of a compact DLL (plus the satisfaction of getting one step close to the inner working on Windows.) Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| ||
|
|