diff options
author | Christopher Faylor <me@cgf.cx> | 2002-08-21 15:45:04 +0000 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2002-08-21 15:45:04 +0000 |
commit | d3106bef0a93865a9c24bd09d39e42c53029b3f8 (patch) | |
tree | a99fbae70f36d4c7f36af8741086d4133cbb39aa /winsup/doc/dll.sgml | |
parent | 62012a3f3134ff4860685b09b50fed01ef326972 (diff) | |
download | cygnal-d3106bef0a93865a9c24bd09d39e42c53029b3f8.tar.gz cygnal-d3106bef0a93865a9c24bd09d39e42c53029b3f8.tar.bz2 cygnal-d3106bef0a93865a9c24bd09d39e42c53029b3f8.zip |
* dll.sgml: Refine dll build instructions.
* ntsec.html: Correct some typos.
Diffstat (limited to 'winsup/doc/dll.sgml')
-rw-r--r-- | winsup/doc/dll.sgml | 62 |
1 files changed, 25 insertions, 37 deletions
diff --git a/winsup/doc/dll.sgml b/winsup/doc/dll.sgml index 274f12926..724c42d06 100644 --- a/winsup/doc/dll.sgml +++ b/winsup/doc/dll.sgml @@ -41,52 +41,40 @@ For this example, we'll use a single file <para>Now compile everything to objects:</para> -<screen> -gcc -c myprog.c -gcc -c mydll.c -</screen> +<screen>gcc -c myprog.c +gcc -c mydll.c</screen> -<para>Unfortunately, the process for building a dll is, well, convoluted. -You have to run five commands, like this:</para> +<para>Fortunately, with the latest gcc and binutils the process for building a dll +is now much simpler. Say you want to build this minimal function in mydll.c:</para> -<screen> -gcc -s -Wl,--base-file,mydll.base -o mydll.dll mydll.o -Wl,-e,_mydll_init@12 -dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp --dllname mydll.dll -gcc -s -Wl,--base-file,mydll.base,mydll.exp -o mydll.dll mydll.o -Wl,-e,_mydll_init@12 -dlltool --base-file mydll.base --def mydll.def --output-exp mydll.exp --dllname mydll.dll -gcc -Wl,mydll.exp -o mydll.dll mydll.o -Wl,-e,_mydll_init@12 -</screen> +<screen>int WINAPI +mydll_init(HANDLE h, DWORD reason, void *foo) +{ + return 1; +}</screen> -<para>The extra steps give <filename>dlltool</filename> the -opportunity to generate the extra sections (exports and relocation) -that a dll needs. After this, you build the import library:</para> +<para>First compile mydll.c to object code:</para> -<screen> -dlltool --def mydll.def --dllname mydll.dll --output-lib mydll.a -</screen> +<screen>gcc -c mydll.c</screen> -<para>Now, when you build your program, you link against the import -library:</para> +<para>Then, tell gcc that it is building a shared library:</para> -<screen> -gcc -o myprog myprog.o mydll.a -</screen> +<screen>gcc -shared -o mydll.dll mydll.o</screen> -<para>Note that we linked with <command>-e _mydll_init@12</command>. -This tells the OS what the DLL's "entry point" is, and this is a -special function that coordinates bringing the dll to life withing the -OS. The minimum function looks like this:</para> - -<screen> -#include <windows.h> +<para>That's it! However, if you are building a dll as an export library, +you will probably want to use the complete syntax:</para> -int WINAPI -mydll_init(HANDLE h, DWORD reason, void *foo) -{ - return 1; -} -</screen> +<screen>gcc -shared -o cyg${module}.dll \ + -Wl,--out-implib=lib${module}.dll.a \ + -Wl,--export-all-symbols \ + -Wl,--enable-auto-import \ + -Wl,--whole-archive ${old_lib} \ + -Wl,--no-whole-archive ${dependency_libs}</screen> +<para>Where ${module} is the name of your DLL, ${old_lib} are all +your object files, bundled together in static libs or single object +files and the ${dependency_libs} are import libs you need to +link against, e.g '-lpng -lz -L/usr/local/special -lmyspeciallib'.</para> </sect2> <sect2 id="dll-link"><title>Linking Against DLLs</title> |