annotate gcc/ada/doc/gnat_ugn/platform_specific_information.rst @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents 84e7813d76e9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 .. role:: switch(samp)
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 .. -- Non-breaking space in running text
kono
parents:
diff changeset
4 -- E.g. Ada |nbsp| 95
kono
parents:
diff changeset
5
kono
parents:
diff changeset
6 .. |nbsp| unicode:: 0xA0
kono
parents:
diff changeset
7 :trim:
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 .. _Platform_Specific_Information:
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 *****************************
kono
parents:
diff changeset
12 Platform-Specific Information
kono
parents:
diff changeset
13 *****************************
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 This appendix contains information relating to the implementation
kono
parents:
diff changeset
16 of run-time libraries on various platforms and also covers
kono
parents:
diff changeset
17 topics related to the GNAT implementation on Windows and Mac OS.
kono
parents:
diff changeset
18
kono
parents:
diff changeset
19 .. _`Run_Time_Libraries`:
kono
parents:
diff changeset
20
kono
parents:
diff changeset
21 Run-Time Libraries
kono
parents:
diff changeset
22 ==================
kono
parents:
diff changeset
23
kono
parents:
diff changeset
24 .. index:: Tasking and threads libraries
kono
parents:
diff changeset
25 .. index:: Threads libraries and tasking
kono
parents:
diff changeset
26 .. index:: Run-time libraries (platform-specific information)
kono
parents:
diff changeset
27
kono
parents:
diff changeset
28 The GNAT run-time implementation may vary with respect to both the
kono
parents:
diff changeset
29 underlying threads library and the exception-handling scheme.
kono
parents:
diff changeset
30 For threads support, the default run-time will bind to the thread
kono
parents:
diff changeset
31 package of the underlying operating system.
kono
parents:
diff changeset
32
kono
parents:
diff changeset
33 For exception handling, either or both of two models are supplied:
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 .. index:: Zero-Cost Exceptions
kono
parents:
diff changeset
36 .. index:: ZCX (Zero-Cost Exceptions)
kono
parents:
diff changeset
37
kono
parents:
diff changeset
38 * **Zero-Cost Exceptions** ("ZCX"),
kono
parents:
diff changeset
39 which uses binder-generated tables that
kono
parents:
diff changeset
40 are interrogated at run time to locate a handler.
kono
parents:
diff changeset
41
kono
parents:
diff changeset
42 .. index:: setjmp/longjmp Exception Model
kono
parents:
diff changeset
43 .. index:: SJLJ (setjmp/longjmp Exception Model)
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 * **setjmp / longjmp** ('SJLJ'),
kono
parents:
diff changeset
46 which uses dynamically-set data to establish
kono
parents:
diff changeset
47 the set of handlers
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 Most programs should experience a substantial speed improvement by
kono
parents:
diff changeset
50 being compiled with a ZCX run-time.
kono
parents:
diff changeset
51 This is especially true for
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
52 tasking applications or applications with many exception handlers.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
53 Note however that the ZCX run-time does not support asynchronous abort
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
54 of tasks (``abort`` and ``select-then-abort`` constructs) and will instead
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
55 implement abort by polling points in the runtime. You can also add additional
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
56 polling points explicitly if needed in your application via ``pragma
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
57 Abort_Defer``.
111
kono
parents:
diff changeset
58
kono
parents:
diff changeset
59 This section summarizes which combinations of threads and exception support
kono
parents:
diff changeset
60 are supplied on various GNAT platforms.
kono
parents:
diff changeset
61
kono
parents:
diff changeset
62 .. _Summary_of_Run-Time_Configurations:
kono
parents:
diff changeset
63
kono
parents:
diff changeset
64 Summary of Run-Time Configurations
kono
parents:
diff changeset
65 ----------------------------------
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 +-----------------+--------------+-------------------------+------------+
kono
parents:
diff changeset
68 | Platform | Run-Time | Tasking | Exceptions |
kono
parents:
diff changeset
69 +=================+==============+=========================+============+
kono
parents:
diff changeset
70 | GNU/Linux | rts-native | pthread library | ZCX |
kono
parents:
diff changeset
71 | | (default) | | |
kono
parents:
diff changeset
72 | +--------------+-------------------------+------------+
kono
parents:
diff changeset
73 | | rts-sjlj | pthread library | SJLJ |
kono
parents:
diff changeset
74 +-----------------+--------------+-------------------------+------------+
kono
parents:
diff changeset
75 | Windows | rts-native | native Win32 threads | ZCX |
kono
parents:
diff changeset
76 | | (default) | | |
kono
parents:
diff changeset
77 | +--------------+-------------------------+------------+
kono
parents:
diff changeset
78 | | rts-sjlj | native Win32 threads | SJLJ |
kono
parents:
diff changeset
79 +-----------------+--------------+-------------------------+------------+
kono
parents:
diff changeset
80 | Mac OS | rts-native | pthread library | ZCX |
kono
parents:
diff changeset
81 +-----------------+--------------+-------------------------+------------+
kono
parents:
diff changeset
82
kono
parents:
diff changeset
83
kono
parents:
diff changeset
84 .. _Specifying_a_Run-Time_Library:
kono
parents:
diff changeset
85
kono
parents:
diff changeset
86 Specifying a Run-Time Library
kono
parents:
diff changeset
87 =============================
kono
parents:
diff changeset
88
kono
parents:
diff changeset
89 The :file:`adainclude` subdirectory containing the sources of the GNAT
kono
parents:
diff changeset
90 run-time library, and the :file:`adalib` subdirectory containing the
kono
parents:
diff changeset
91 :file:`ALI` files and the static and/or shared GNAT library, are located
kono
parents:
diff changeset
92 in the gcc target-dependent area:
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 ::
kono
parents:
diff changeset
96
kono
parents:
diff changeset
97 target=$prefix/lib/gcc/gcc-*dumpmachine*/gcc-*dumpversion*/
kono
parents:
diff changeset
98
kono
parents:
diff changeset
99 As indicated above, on some platforms several run-time libraries are supplied.
kono
parents:
diff changeset
100 These libraries are installed in the target dependent area and
kono
parents:
diff changeset
101 contain a complete source and binary subdirectory. The detailed description
kono
parents:
diff changeset
102 below explains the differences between the different libraries in terms of
kono
parents:
diff changeset
103 their thread support.
kono
parents:
diff changeset
104
kono
parents:
diff changeset
105 The default run-time library (when GNAT is installed) is *rts-native*.
kono
parents:
diff changeset
106 This default run-time is selected by the means of soft links.
kono
parents:
diff changeset
107 For example on x86-linux:
kono
parents:
diff changeset
108
kono
parents:
diff changeset
109 .. --
kono
parents:
diff changeset
110 -- $(target-dir)
kono
parents:
diff changeset
111 -- |
kono
parents:
diff changeset
112 -- +--- adainclude----------+
kono
parents:
diff changeset
113 -- | |
kono
parents:
diff changeset
114 -- +--- adalib-----------+ |
kono
parents:
diff changeset
115 -- | | |
kono
parents:
diff changeset
116 -- +--- rts-native | |
kono
parents:
diff changeset
117 -- | | | |
kono
parents:
diff changeset
118 -- | +--- adainclude <---+
kono
parents:
diff changeset
119 -- | | |
kono
parents:
diff changeset
120 -- | +--- adalib <----+
kono
parents:
diff changeset
121 -- |
kono
parents:
diff changeset
122 -- +--- rts-sjlj
kono
parents:
diff changeset
123 -- |
kono
parents:
diff changeset
124 -- +--- adainclude
kono
parents:
diff changeset
125 -- |
kono
parents:
diff changeset
126 -- +--- adalib
kono
parents:
diff changeset
127
kono
parents:
diff changeset
128 .. only:: html or latex
kono
parents:
diff changeset
129
kono
parents:
diff changeset
130 .. image:: rtlibrary-structure.png
kono
parents:
diff changeset
131
kono
parents:
diff changeset
132 .. only:: not (html or latex)
kono
parents:
diff changeset
133
kono
parents:
diff changeset
134 ::
kono
parents:
diff changeset
135
kono
parents:
diff changeset
136 $(target-dir)
kono
parents:
diff changeset
137 __/ / \ \___
kono
parents:
diff changeset
138 _______/ / \ \_________________
kono
parents:
diff changeset
139 / / \ \
kono
parents:
diff changeset
140 / / \ \
kono
parents:
diff changeset
141 ADAINCLUDE ADALIB rts-native rts-sjlj
kono
parents:
diff changeset
142 : : / \ / \
kono
parents:
diff changeset
143 : : / \ / \
kono
parents:
diff changeset
144 : : / \ / \
kono
parents:
diff changeset
145 : : / \ / \
kono
parents:
diff changeset
146 +-------------> adainclude adalib adainclude adalib
kono
parents:
diff changeset
147 : ^
kono
parents:
diff changeset
148 : :
kono
parents:
diff changeset
149 +---------------------+
kono
parents:
diff changeset
150
kono
parents:
diff changeset
151 Run-Time Library Directory Structure
kono
parents:
diff changeset
152 (Upper-case names and dotted/dashed arrows represent soft links)
kono
parents:
diff changeset
153
kono
parents:
diff changeset
154 If the *rts-sjlj* library is to be selected on a permanent basis,
kono
parents:
diff changeset
155 these soft links can be modified with the following commands:
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 ::
kono
parents:
diff changeset
158
kono
parents:
diff changeset
159 $ cd $target
kono
parents:
diff changeset
160 $ rm -f adainclude adalib
kono
parents:
diff changeset
161 $ ln -s rts-sjlj/adainclude adainclude
kono
parents:
diff changeset
162 $ ln -s rts-sjlj/adalib adalib
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 Alternatively, you can specify :file:`rts-sjlj/adainclude` in the file
kono
parents:
diff changeset
165 :file:`$target/ada_source_path` and :file:`rts-sjlj/adalib` in
kono
parents:
diff changeset
166 :file:`$target/ada_object_path`.
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 .. index:: --RTS option
kono
parents:
diff changeset
169
kono
parents:
diff changeset
170 Selecting another run-time library temporarily can be
kono
parents:
diff changeset
171 achieved by using the :switch:`--RTS` switch, e.g., :switch:`--RTS=sjlj`
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173
kono
parents:
diff changeset
174 .. _Choosing_the_Scheduling_Policy:
kono
parents:
diff changeset
175
kono
parents:
diff changeset
176 .. index:: SCHED_FIFO scheduling policy
kono
parents:
diff changeset
177 .. index:: SCHED_RR scheduling policy
kono
parents:
diff changeset
178 .. index:: SCHED_OTHER scheduling policy
kono
parents:
diff changeset
179
kono
parents:
diff changeset
180 Choosing the Scheduling Policy
kono
parents:
diff changeset
181 ------------------------------
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 When using a POSIX threads implementation, you have a choice of several
kono
parents:
diff changeset
184 scheduling policies: ``SCHED_FIFO``, ``SCHED_RR`` and ``SCHED_OTHER``.
kono
parents:
diff changeset
185
kono
parents:
diff changeset
186 Typically, the default is ``SCHED_OTHER``, while using ``SCHED_FIFO``
kono
parents:
diff changeset
187 or ``SCHED_RR`` requires special (e.g., root) privileges.
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 .. index:: pragma Time_Slice
kono
parents:
diff changeset
190 .. index:: -T0 option
kono
parents:
diff changeset
191 .. index:: pragma Task_Dispatching_Policy
kono
parents:
diff changeset
192
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 By default, GNAT uses the ``SCHED_OTHER`` policy. To specify
kono
parents:
diff changeset
195 ``SCHED_FIFO``,
kono
parents:
diff changeset
196 you can use one of the following:
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 * ``pragma Time_Slice (0.0)``
kono
parents:
diff changeset
199 * the corresponding binder option :switch:`-T0`
kono
parents:
diff changeset
200 * ``pragma Task_Dispatching_Policy (FIFO_Within_Priorities)``
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202
kono
parents:
diff changeset
203 To specify ``SCHED_RR``,
kono
parents:
diff changeset
204 you should use ``pragma Time_Slice`` with a
kono
parents:
diff changeset
205 value greater than 0.0, or else use the corresponding :switch:`-T`
kono
parents:
diff changeset
206 binder option.
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208
kono
parents:
diff changeset
209 To make sure a program is running as root, you can put something like
kono
parents:
diff changeset
210 this in a library package body in your application:
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 .. code-block:: ada
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 function geteuid return Integer;
kono
parents:
diff changeset
215 pragma Import (C, geteuid, "geteuid");
kono
parents:
diff changeset
216 Ignore : constant Boolean :=
kono
parents:
diff changeset
217 (if geteuid = 0 then True else raise Program_Error with "must be root");
kono
parents:
diff changeset
218
kono
parents:
diff changeset
219 It gets the effective user id, and if it's not 0 (i.e. root), it raises
kono
parents:
diff changeset
220 Program_Error.
kono
parents:
diff changeset
221
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
222 .. index:: Linux
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
223 .. index:: GNU/Linux
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
224
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
225 .. _GNU_Linux_Topics:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
226
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
227 GNU/Linux Topics
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
228 ================
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
229
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
230 This section describes topics that are specific to GNU/Linux platforms.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
231
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
232 .. _Required_packages_on_GNU_Linux:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
233
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
234 Required Packages on GNU/Linux
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
235 ------------------------------
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
236
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
237 GNAT requires the C library developer's package to be installed.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
238 The name of of that package depends on your GNU/Linux distribution:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
239
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
240 * RedHat, SUSE: ``glibc-devel``;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
241 * Debian, Ubuntu: ``libc6-dev`` (normally installed by default).
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
242
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
243 If using the 32-bit version of GNAT on a 64-bit version of GNU/Linux,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
244 you'll need the 32-bit version of the following packages:
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
245
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
246 * RedHat, SUSE: ``glibc.i686``, ``glibc-devel.i686``, ``ncurses-libs.i686``
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
247 * Debian, Ubuntu: ``libc6:i386``, ``libc6-dev:i386``, ``lib32ncursesw5``
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
248
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
249 Other GNU/Linux distributions might be choosing a different name
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
250 for those packages.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
251
111
kono
parents:
diff changeset
252 .. index:: Windows
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 .. _Microsoft_Windows_Topics:
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 Microsoft Windows Topics
kono
parents:
diff changeset
257 ========================
kono
parents:
diff changeset
258
kono
parents:
diff changeset
259 This section describes topics that are specific to the Microsoft Windows
kono
parents:
diff changeset
260 platforms.
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
263 .. only:: PRO
111
kono
parents:
diff changeset
264
kono
parents:
diff changeset
265 .. rubric:: Installing from the Command Line
kono
parents:
diff changeset
266
kono
parents:
diff changeset
267 By default the GNAT installers display a GUI that prompts you to enter
kono
parents:
diff changeset
268 the installation path and similar information, and then guides you through the
kono
parents:
diff changeset
269 installation process. It is also possible to perform silent installations
kono
parents:
diff changeset
270 using the command-line interface.
kono
parents:
diff changeset
271
kono
parents:
diff changeset
272 In order to install one of the GNAT installers from the command
kono
parents:
diff changeset
273 line you should pass parameter :switch:`/S` (and, optionally,
kono
parents:
diff changeset
274 :switch:`/D=<directory>`) as command-line arguments.
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 For example, for an unattended installation of
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
277 GNAT 19.2 into the default directory :file:`C:\\GNATPRO\\19.2` you
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
278 would run::
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
279
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
280 gnatpro-19.2-x86-windows-bin /S
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
281
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
282 To install into a custom directory, say, :file:`C:\\TOOLS\\GNATPRO\\19.2`::
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
283
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
284 gnatpro-19.2-x86-windows-bin /S /D=C:\TOOLS\GNATPRO\19.2
111
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 You can use the same syntax for all installers.
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 Note that unattended installations don't modify system path, nor create file
kono
parents:
diff changeset
289 associations, so such activities need to be done by hand.
kono
parents:
diff changeset
290
kono
parents:
diff changeset
291
kono
parents:
diff changeset
292 .. _Using_GNAT_on_Windows:
kono
parents:
diff changeset
293
kono
parents:
diff changeset
294 Using GNAT on Windows
kono
parents:
diff changeset
295 ---------------------
kono
parents:
diff changeset
296
kono
parents:
diff changeset
297 One of the strengths of the GNAT technology is that its tool set
kono
parents:
diff changeset
298 (``gcc``, ``gnatbind``, ``gnatlink``, ``gnatmake``, the
kono
parents:
diff changeset
299 ``gdb`` debugger, etc.) is used in the same way regardless of the
kono
parents:
diff changeset
300 platform.
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 On Windows this tool set is complemented by a number of Microsoft-specific
kono
parents:
diff changeset
303 tools that have been provided to facilitate interoperability with Windows
kono
parents:
diff changeset
304 when this is required. With these tools:
kono
parents:
diff changeset
305
kono
parents:
diff changeset
306
kono
parents:
diff changeset
307 * You can build applications using the ``CONSOLE`` or ``WINDOWS``
kono
parents:
diff changeset
308 subsystems.
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 * You can use any Dynamically Linked Library (DLL) in your Ada code (both
kono
parents:
diff changeset
311 relocatable and non-relocatable DLLs are supported).
kono
parents:
diff changeset
312
kono
parents:
diff changeset
313 * You can build Ada DLLs for use in other applications. These applications
kono
parents:
diff changeset
314 can be written in a language other than Ada (e.g., C, C++, etc). Again both
kono
parents:
diff changeset
315 relocatable and non-relocatable Ada DLLs are supported.
kono
parents:
diff changeset
316
kono
parents:
diff changeset
317 * You can include Windows resources in your Ada application.
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 * You can use or create COM/DCOM objects.
kono
parents:
diff changeset
320
kono
parents:
diff changeset
321 Immediately below are listed all known general GNAT-for-Windows restrictions.
kono
parents:
diff changeset
322 Other restrictions about specific features like Windows Resources and DLLs
kono
parents:
diff changeset
323 are listed in separate sections below.
kono
parents:
diff changeset
324
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 * It is not possible to use ``GetLastError`` and ``SetLastError``
kono
parents:
diff changeset
327 when tasking, protected records, or exceptions are used. In these
kono
parents:
diff changeset
328 cases, in order to implement Ada semantics, the GNAT run-time system
kono
parents:
diff changeset
329 calls certain Win32 routines that set the last error variable to 0 upon
kono
parents:
diff changeset
330 success. It should be possible to use ``GetLastError`` and
kono
parents:
diff changeset
331 ``SetLastError`` when tasking, protected record, and exception
kono
parents:
diff changeset
332 features are not used, but it is not guaranteed to work.
kono
parents:
diff changeset
333
kono
parents:
diff changeset
334 * It is not possible to link against Microsoft C++ libraries except for
kono
parents:
diff changeset
335 import libraries. Interfacing must be done by the mean of DLLs.
kono
parents:
diff changeset
336
kono
parents:
diff changeset
337 * It is possible to link against Microsoft C libraries. Yet the preferred
kono
parents:
diff changeset
338 solution is to use C/C++ compiler that comes with GNAT, since it
kono
parents:
diff changeset
339 doesn't require having two different development environments and makes the
kono
parents:
diff changeset
340 inter-language debugging experience smoother.
kono
parents:
diff changeset
341
kono
parents:
diff changeset
342 * When the compilation environment is located on FAT32 drives, users may
kono
parents:
diff changeset
343 experience recompilations of the source files that have not changed if
kono
parents:
diff changeset
344 Daylight Saving Time (DST) state has changed since the last time files
kono
parents:
diff changeset
345 were compiled. NTFS drives do not have this problem.
kono
parents:
diff changeset
346
kono
parents:
diff changeset
347 * No components of the GNAT toolset use any entries in the Windows
kono
parents:
diff changeset
348 registry. The only entries that can be created are file associations and
kono
parents:
diff changeset
349 PATH settings, provided the user has chosen to create them at installation
kono
parents:
diff changeset
350 time, as well as some minimal book-keeping information needed to correctly
kono
parents:
diff changeset
351 uninstall or integrate different GNAT products.
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353
kono
parents:
diff changeset
354 .. _Using_a_network_installation_of_GNAT:
kono
parents:
diff changeset
355
kono
parents:
diff changeset
356 Using a network installation of GNAT
kono
parents:
diff changeset
357 ------------------------------------
kono
parents:
diff changeset
358
kono
parents:
diff changeset
359 Make sure the system on which GNAT is installed is accessible from the
kono
parents:
diff changeset
360 current machine, i.e., the install location is shared over the network.
kono
parents:
diff changeset
361 Shared resources are accessed on Windows by means of UNC paths, which
kono
parents:
diff changeset
362 have the format ``\\\\server\\sharename\\path``
kono
parents:
diff changeset
363
kono
parents:
diff changeset
364 In order to use such a network installation, simply add the UNC path of the
kono
parents:
diff changeset
365 :file:`bin` directory of your GNAT installation in front of your PATH. For
kono
parents:
diff changeset
366 example, if GNAT is installed in :file:`\\GNAT` directory of a share location
kono
parents:
diff changeset
367 called :file:`c-drive` on a machine :file:`LOKI`, the following command will
kono
parents:
diff changeset
368 make it available:
kono
parents:
diff changeset
369
kono
parents:
diff changeset
370 ::
kono
parents:
diff changeset
371
kono
parents:
diff changeset
372 $ path \\loki\c-drive\gnat\bin;%path%`
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 Be aware that every compilation using the network installation results in the
kono
parents:
diff changeset
375 transfer of large amounts of data across the network and will likely cause
kono
parents:
diff changeset
376 serious performance penalty.
kono
parents:
diff changeset
377
kono
parents:
diff changeset
378 .. _CONSOLE_and_WINDOWS_subsystems:
kono
parents:
diff changeset
379
kono
parents:
diff changeset
380 CONSOLE and WINDOWS subsystems
kono
parents:
diff changeset
381 ------------------------------
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 .. index:: CONSOLE Subsystem
kono
parents:
diff changeset
384 .. index:: WINDOWS Subsystem
kono
parents:
diff changeset
385 .. index:: -mwindows
kono
parents:
diff changeset
386
kono
parents:
diff changeset
387 There are two main subsystems under Windows. The ``CONSOLE`` subsystem
kono
parents:
diff changeset
388 (which is the default subsystem) will always create a console when
kono
parents:
diff changeset
389 launching the application. This is not something desirable when the
kono
parents:
diff changeset
390 application has a Windows GUI. To get rid of this console the
kono
parents:
diff changeset
391 application must be using the ``WINDOWS`` subsystem. To do so
kono
parents:
diff changeset
392 the :switch:`-mwindows` linker option must be specified.
kono
parents:
diff changeset
393
kono
parents:
diff changeset
394 ::
kono
parents:
diff changeset
395
kono
parents:
diff changeset
396 $ gnatmake winprog -largs -mwindows
kono
parents:
diff changeset
397
kono
parents:
diff changeset
398 .. _Temporary_Files:
kono
parents:
diff changeset
399
kono
parents:
diff changeset
400 Temporary Files
kono
parents:
diff changeset
401 ---------------
kono
parents:
diff changeset
402
kono
parents:
diff changeset
403 .. index:: Temporary files
kono
parents:
diff changeset
404
kono
parents:
diff changeset
405 It is possible to control where temporary files gets created by setting
kono
parents:
diff changeset
406 the :envvar:`TMP` environment variable. The file will be created:
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 * Under the directory pointed to by the :envvar:`TMP` environment variable if
kono
parents:
diff changeset
409 this directory exists.
kono
parents:
diff changeset
410
kono
parents:
diff changeset
411 * Under :file:`c:\\temp`, if the :envvar:`TMP` environment variable is not
kono
parents:
diff changeset
412 set (or not pointing to a directory) and if this directory exists.
kono
parents:
diff changeset
413
kono
parents:
diff changeset
414 * Under the current working directory otherwise.
kono
parents:
diff changeset
415
kono
parents:
diff changeset
416 This allows you to determine exactly where the temporary
kono
parents:
diff changeset
417 file will be created. This is particularly useful in networked
kono
parents:
diff changeset
418 environments where you may not have write access to some
kono
parents:
diff changeset
419 directories.
kono
parents:
diff changeset
420
kono
parents:
diff changeset
421 Disabling Command Line Argument Expansion
kono
parents:
diff changeset
422 -----------------------------------------
kono
parents:
diff changeset
423
kono
parents:
diff changeset
424 .. index:: Command Line Argument Expansion
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 By default, an executable compiled for the Windows platform will do
kono
parents:
diff changeset
427 the following postprocessing on the arguments passed on the command
kono
parents:
diff changeset
428 line:
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 * If the argument contains the characters ``*`` and/or ``?``, then
kono
parents:
diff changeset
431 file expansion will be attempted. For example, if the current directory
kono
parents:
diff changeset
432 contains :file:`a.txt` and :file:`b.txt`, then when calling::
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 $ my_ada_program *.txt
kono
parents:
diff changeset
435
kono
parents:
diff changeset
436 The following arguments will effectively be passed to the main program
kono
parents:
diff changeset
437 (for example when using ``Ada.Command_Line.Argument``)::
kono
parents:
diff changeset
438
kono
parents:
diff changeset
439 Ada.Command_Line.Argument (1) -> "a.txt"
kono
parents:
diff changeset
440 Ada.Command_Line.Argument (2) -> "b.txt"
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 * Filename expansion can be disabled for a given argument by using single
kono
parents:
diff changeset
443 quotes. Thus, calling::
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 $ my_ada_program '*.txt'
kono
parents:
diff changeset
446
kono
parents:
diff changeset
447 will result in::
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 Ada.Command_Line.Argument (1) -> "*.txt"
kono
parents:
diff changeset
450
kono
parents:
diff changeset
451 Note that if the program is launched from a shell such as Cygwin Bash
kono
parents:
diff changeset
452 then quote removal might be performed by the shell.
kono
parents:
diff changeset
453
kono
parents:
diff changeset
454 In some contexts it might be useful to disable this feature (for example if
kono
parents:
diff changeset
455 the program performs its own argument expansion). In order to do this, a C
kono
parents:
diff changeset
456 symbol needs to be defined and set to ``0``. You can do this by
kono
parents:
diff changeset
457 adding the following code fragment in one of your Ada units:
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 .. code-block:: ada
kono
parents:
diff changeset
460
kono
parents:
diff changeset
461 Do_Argv_Expansion : Integer := 0;
kono
parents:
diff changeset
462 pragma Export (C, Do_Argv_Expansion, "__gnat_do_argv_expansion");
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 The results of previous examples will be respectively::
kono
parents:
diff changeset
465
kono
parents:
diff changeset
466 Ada.Command_Line.Argument (1) -> "*.txt"
kono
parents:
diff changeset
467
kono
parents:
diff changeset
468 and::
kono
parents:
diff changeset
469
kono
parents:
diff changeset
470 Ada.Command_Line.Argument (1) -> "'*.txt'"
kono
parents:
diff changeset
471
kono
parents:
diff changeset
472
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
473 Windows Socket Timeouts
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
474 -----------------------
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
475
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
476 Microsoft Windows desktops older than ``8.0`` and Microsoft Windows Servers
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
477 older than ``2019`` set a socket timeout 500 milliseconds longer than the value
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
478 set by setsockopt with ``SO_RCVTIMEO`` and ``SO_SNDTIMEO`` options. The GNAT
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
479 runtime makes a correction for the difference in the corresponding Windows
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
480 versions. For Windows Server starting with version ``2019``, the user must
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
481 provide a manifest file for the GNAT runtime to be able to recognize that
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
482 the Windows version does not need the timeout correction. The manifest file
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
483 should be located in the same directory as the executable file, and its file
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
484 name must match the executable name suffixed by ``.manifest``. For example,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
485 if the executable name is :file:`sock_wto.exe`, then the manifest file name
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
486 has to be :file:`sock_wto.exe.manifest`. The manifest file must contain at
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
487 least the following data::
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
488
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
489 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
490 <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
491 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
492 <application>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
493 <!-- Windows Vista -->
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
494 <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
495 <!-- Windows 7 -->
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
496 <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
497 <!-- Windows 8 -->
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
498 <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
499 <!-- Windows 8.1 -->
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
500 <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
501 <!-- Windows 10 -->
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
502 <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
503 </application>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
504 </compatibility>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
505 </assembly>
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
506
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
507 Without the manifest file, the socket timeout is going to be overcorrected on
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
508 these Windows Server versions and the actual time is going to be 500
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
509 milliseconds shorter than what was set with GNAT.Sockets.Set_Socket_Option.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
510 Note that on Microsoft Windows versions where correction is necessary, there
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
511 is no way to set a socket timeout shorter than 500 ms. If a socket timeout
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
512 shorter than 500 ms is needed on these Windows versions, a call to
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
513 Check_Selector should be added before any socket read or write operations.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
514
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
515
111
kono
parents:
diff changeset
516 .. _Mixed-Language_Programming_on_Windows:
kono
parents:
diff changeset
517
kono
parents:
diff changeset
518 Mixed-Language Programming on Windows
kono
parents:
diff changeset
519 -------------------------------------
kono
parents:
diff changeset
520
kono
parents:
diff changeset
521 Developing pure Ada applications on Windows is no different than on
kono
parents:
diff changeset
522 other GNAT-supported platforms. However, when developing or porting an
kono
parents:
diff changeset
523 application that contains a mix of Ada and C/C++, the choice of your
kono
parents:
diff changeset
524 Windows C/C++ development environment conditions your overall
kono
parents:
diff changeset
525 interoperability strategy.
kono
parents:
diff changeset
526
kono
parents:
diff changeset
527 If you use ``gcc`` or Microsoft C to compile the non-Ada part of
kono
parents:
diff changeset
528 your application, there are no Windows-specific restrictions that
kono
parents:
diff changeset
529 affect the overall interoperability with your Ada code. If you do want
kono
parents:
diff changeset
530 to use the Microsoft tools for your C++ code, you have two choices:
kono
parents:
diff changeset
531
kono
parents:
diff changeset
532 * Encapsulate your C++ code in a DLL to be linked with your Ada
kono
parents:
diff changeset
533 application. In this case, use the Microsoft or whatever environment to
kono
parents:
diff changeset
534 build the DLL and use GNAT to build your executable
kono
parents:
diff changeset
535 (:ref:`Using_DLLs_with_GNAT`).
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 * Or you can encapsulate your Ada code in a DLL to be linked with the
kono
parents:
diff changeset
538 other part of your application. In this case, use GNAT to build the DLL
kono
parents:
diff changeset
539 (:ref:`Building_DLLs_with_GNAT_Project_files`) and use the Microsoft
kono
parents:
diff changeset
540 or whatever environment to build your executable.
kono
parents:
diff changeset
541
kono
parents:
diff changeset
542 In addition to the description about C main in
kono
parents:
diff changeset
543 :ref:`Mixed_Language_Programming` section, if the C main uses a
kono
parents:
diff changeset
544 stand-alone library it is required on x86-windows to
kono
parents:
diff changeset
545 setup the SEH context. For this the C main must looks like this:
kono
parents:
diff changeset
546
kono
parents:
diff changeset
547
kono
parents:
diff changeset
548 .. code-block:: c
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 /* main.c */
kono
parents:
diff changeset
551 extern void adainit (void);
kono
parents:
diff changeset
552 extern void adafinal (void);
kono
parents:
diff changeset
553 extern void __gnat_initialize(void*);
kono
parents:
diff changeset
554 extern void call_to_ada (void);
kono
parents:
diff changeset
555
kono
parents:
diff changeset
556 int main (int argc, char *argv[])
kono
parents:
diff changeset
557 {
kono
parents:
diff changeset
558 int SEH [2];
kono
parents:
diff changeset
559
kono
parents:
diff changeset
560 /* Initialize the SEH context */
kono
parents:
diff changeset
561 __gnat_initialize (&SEH);
kono
parents:
diff changeset
562
kono
parents:
diff changeset
563 adainit();
kono
parents:
diff changeset
564
kono
parents:
diff changeset
565 /* Then call Ada services in the stand-alone library */
kono
parents:
diff changeset
566
kono
parents:
diff changeset
567 call_to_ada();
kono
parents:
diff changeset
568
kono
parents:
diff changeset
569 adafinal();
kono
parents:
diff changeset
570 }
kono
parents:
diff changeset
571
kono
parents:
diff changeset
572 Note that this is not needed on x86_64-windows where the Windows
kono
parents:
diff changeset
573 native SEH support is used.
kono
parents:
diff changeset
574
kono
parents:
diff changeset
575
kono
parents:
diff changeset
576 .. _Windows_Calling_Conventions:
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 Windows Calling Conventions
kono
parents:
diff changeset
579 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
580
kono
parents:
diff changeset
581 .. index:: Stdcall
kono
parents:
diff changeset
582 .. index:: APIENTRY
kono
parents:
diff changeset
583
kono
parents:
diff changeset
584 This section pertain only to Win32. On Win64 there is a single native
kono
parents:
diff changeset
585 calling convention. All convention specifiers are ignored on this
kono
parents:
diff changeset
586 platform.
kono
parents:
diff changeset
587
kono
parents:
diff changeset
588 When a subprogram ``F`` (caller) calls a subprogram ``G``
kono
parents:
diff changeset
589 (callee), there are several ways to push ``G``\ 's parameters on the
kono
parents:
diff changeset
590 stack and there are several possible scenarios to clean up the stack
kono
parents:
diff changeset
591 upon ``G``\ 's return. A calling convention is an agreed upon software
kono
parents:
diff changeset
592 protocol whereby the responsibilities between the caller (``F``) and
kono
parents:
diff changeset
593 the callee (``G``) are clearly defined. Several calling conventions
kono
parents:
diff changeset
594 are available for Windows:
kono
parents:
diff changeset
595
kono
parents:
diff changeset
596 * ``C`` (Microsoft defined)
kono
parents:
diff changeset
597
kono
parents:
diff changeset
598 * ``Stdcall`` (Microsoft defined)
kono
parents:
diff changeset
599
kono
parents:
diff changeset
600 * ``Win32`` (GNAT specific)
kono
parents:
diff changeset
601
kono
parents:
diff changeset
602 * ``DLL`` (GNAT specific)
kono
parents:
diff changeset
603
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 .. _C_Calling_Convention:
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 ``C`` Calling Convention
kono
parents:
diff changeset
608 """"""""""""""""""""""""
kono
parents:
diff changeset
609
kono
parents:
diff changeset
610 This is the default calling convention used when interfacing to C/C++
kono
parents:
diff changeset
611 routines compiled with either ``gcc`` or Microsoft Visual C++.
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 In the ``C`` calling convention subprogram parameters are pushed on the
kono
parents:
diff changeset
614 stack by the caller from right to left. The caller itself is in charge of
kono
parents:
diff changeset
615 cleaning up the stack after the call. In addition, the name of a routine
kono
parents:
diff changeset
616 with ``C`` calling convention is mangled by adding a leading underscore.
kono
parents:
diff changeset
617
kono
parents:
diff changeset
618 The name to use on the Ada side when importing (or exporting) a routine
kono
parents:
diff changeset
619 with ``C`` calling convention is the name of the routine. For
kono
parents:
diff changeset
620 instance the C function:
kono
parents:
diff changeset
621
kono
parents:
diff changeset
622 ::
kono
parents:
diff changeset
623
kono
parents:
diff changeset
624 int get_val (long);
kono
parents:
diff changeset
625
kono
parents:
diff changeset
626 should be imported from Ada as follows:
kono
parents:
diff changeset
627
kono
parents:
diff changeset
628 .. code-block:: ada
kono
parents:
diff changeset
629
kono
parents:
diff changeset
630 function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
kono
parents:
diff changeset
631 pragma Import (C, Get_Val, External_Name => "get_val");
kono
parents:
diff changeset
632
kono
parents:
diff changeset
633 Note that in this particular case the ``External_Name`` parameter could
kono
parents:
diff changeset
634 have been omitted since, when missing, this parameter is taken to be the
kono
parents:
diff changeset
635 name of the Ada entity in lower case. When the ``Link_Name`` parameter
kono
parents:
diff changeset
636 is missing, as in the above example, this parameter is set to be the
kono
parents:
diff changeset
637 ``External_Name`` with a leading underscore.
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 When importing a variable defined in C, you should always use the ``C``
kono
parents:
diff changeset
640 calling convention unless the object containing the variable is part of a
kono
parents:
diff changeset
641 DLL (in which case you should use the ``Stdcall`` calling
kono
parents:
diff changeset
642 convention, :ref:`Stdcall_Calling_Convention`).
kono
parents:
diff changeset
643
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 .. _Stdcall_Calling_Convention:
kono
parents:
diff changeset
646
kono
parents:
diff changeset
647 ``Stdcall`` Calling Convention
kono
parents:
diff changeset
648 """"""""""""""""""""""""""""""
kono
parents:
diff changeset
649
kono
parents:
diff changeset
650 This convention, which was the calling convention used for Pascal
kono
parents:
diff changeset
651 programs, is used by Microsoft for all the routines in the Win32 API for
kono
parents:
diff changeset
652 efficiency reasons. It must be used to import any routine for which this
kono
parents:
diff changeset
653 convention was specified.
kono
parents:
diff changeset
654
kono
parents:
diff changeset
655 In the ``Stdcall`` calling convention subprogram parameters are pushed
kono
parents:
diff changeset
656 on the stack by the caller from right to left. The callee (and not the
kono
parents:
diff changeset
657 caller) is in charge of cleaning the stack on routine exit. In addition,
kono
parents:
diff changeset
658 the name of a routine with ``Stdcall`` calling convention is mangled by
kono
parents:
diff changeset
659 adding a leading underscore (as for the ``C`` calling convention) and a
kono
parents:
diff changeset
660 trailing :samp:`@{nn}`, where ``nn`` is the overall size (in
kono
parents:
diff changeset
661 bytes) of the parameters passed to the routine.
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 The name to use on the Ada side when importing a C routine with a
kono
parents:
diff changeset
664 ``Stdcall`` calling convention is the name of the C routine. The leading
kono
parents:
diff changeset
665 underscore and trailing :samp:`@{nn}` are added automatically by
kono
parents:
diff changeset
666 the compiler. For instance the Win32 function:
kono
parents:
diff changeset
667
kono
parents:
diff changeset
668 ::
kono
parents:
diff changeset
669
kono
parents:
diff changeset
670 APIENTRY int get_val (long);
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 should be imported from Ada as follows:
kono
parents:
diff changeset
673
kono
parents:
diff changeset
674 .. code-block:: ada
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
kono
parents:
diff changeset
677 pragma Import (Stdcall, Get_Val);
kono
parents:
diff changeset
678 -- On the x86 a long is 4 bytes, so the Link_Name is "_get_val@4"
kono
parents:
diff changeset
679
kono
parents:
diff changeset
680 As for the ``C`` calling convention, when the ``External_Name``
kono
parents:
diff changeset
681 parameter is missing, it is taken to be the name of the Ada entity in lower
kono
parents:
diff changeset
682 case. If instead of writing the above import pragma you write:
kono
parents:
diff changeset
683
kono
parents:
diff changeset
684 .. code-block:: ada
kono
parents:
diff changeset
685
kono
parents:
diff changeset
686 function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
kono
parents:
diff changeset
687 pragma Import (Stdcall, Get_Val, External_Name => "retrieve_val");
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 then the imported routine is ``_retrieve_val@4``. However, if instead
kono
parents:
diff changeset
690 of specifying the ``External_Name`` parameter you specify the
kono
parents:
diff changeset
691 ``Link_Name`` as in the following example:
kono
parents:
diff changeset
692
kono
parents:
diff changeset
693 .. code-block:: ada
kono
parents:
diff changeset
694
kono
parents:
diff changeset
695 function Get_Val (V : Interfaces.C.long) return Interfaces.C.int;
kono
parents:
diff changeset
696 pragma Import (Stdcall, Get_Val, Link_Name => "retrieve_val");
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 then the imported routine is ``retrieve_val``, that is, there is no
kono
parents:
diff changeset
699 decoration at all. No leading underscore and no Stdcall suffix
kono
parents:
diff changeset
700 :samp:`@{nn}`.
kono
parents:
diff changeset
701
kono
parents:
diff changeset
702 This is especially important as in some special cases a DLL's entry
kono
parents:
diff changeset
703 point name lacks a trailing :samp:`@{nn}` while the exported
kono
parents:
diff changeset
704 name generated for a call has it.
kono
parents:
diff changeset
705
kono
parents:
diff changeset
706 It is also possible to import variables defined in a DLL by using an
kono
parents:
diff changeset
707 import pragma for a variable. As an example, if a DLL contains a
kono
parents:
diff changeset
708 variable defined as:
kono
parents:
diff changeset
709
kono
parents:
diff changeset
710 .. code-block:: c
kono
parents:
diff changeset
711
kono
parents:
diff changeset
712 int my_var;
kono
parents:
diff changeset
713
kono
parents:
diff changeset
714 then, to access this variable from Ada you should write:
kono
parents:
diff changeset
715
kono
parents:
diff changeset
716 .. code-block:: ada
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 My_Var : Interfaces.C.int;
kono
parents:
diff changeset
719 pragma Import (Stdcall, My_Var);
kono
parents:
diff changeset
720
kono
parents:
diff changeset
721 Note that to ease building cross-platform bindings this convention
kono
parents:
diff changeset
722 will be handled as a ``C`` calling convention on non-Windows platforms.
kono
parents:
diff changeset
723
kono
parents:
diff changeset
724
kono
parents:
diff changeset
725 .. _Win32_Calling_Convention:
kono
parents:
diff changeset
726
kono
parents:
diff changeset
727 ``Win32`` Calling Convention
kono
parents:
diff changeset
728 """"""""""""""""""""""""""""
kono
parents:
diff changeset
729
kono
parents:
diff changeset
730 This convention, which is GNAT-specific is fully equivalent to the
kono
parents:
diff changeset
731 ``Stdcall`` calling convention described above.
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733
kono
parents:
diff changeset
734 .. _DLL_Calling_Convention:
kono
parents:
diff changeset
735
kono
parents:
diff changeset
736 ``DLL`` Calling Convention
kono
parents:
diff changeset
737 """"""""""""""""""""""""""
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 This convention, which is GNAT-specific is fully equivalent to the
kono
parents:
diff changeset
740 ``Stdcall`` calling convention described above.
kono
parents:
diff changeset
741
kono
parents:
diff changeset
742
kono
parents:
diff changeset
743 .. _Introduction_to_Dynamic_Link_Libraries_DLLs:
kono
parents:
diff changeset
744
kono
parents:
diff changeset
745 Introduction to Dynamic Link Libraries (DLLs)
kono
parents:
diff changeset
746 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
747
kono
parents:
diff changeset
748 .. index:: DLL
kono
parents:
diff changeset
749
kono
parents:
diff changeset
750 A Dynamically Linked Library (DLL) is a library that can be shared by
kono
parents:
diff changeset
751 several applications running under Windows. A DLL can contain any number of
kono
parents:
diff changeset
752 routines and variables.
kono
parents:
diff changeset
753
kono
parents:
diff changeset
754 One advantage of DLLs is that you can change and enhance them without
kono
parents:
diff changeset
755 forcing all the applications that depend on them to be relinked or
kono
parents:
diff changeset
756 recompiled. However, you should be aware than all calls to DLL routines are
kono
parents:
diff changeset
757 slower since, as you will understand below, such calls are indirect.
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 To illustrate the remainder of this section, suppose that an application
kono
parents:
diff changeset
760 wants to use the services of a DLL :file:`API.dll`. To use the services
kono
parents:
diff changeset
761 provided by :file:`API.dll` you must statically link against the DLL or
kono
parents:
diff changeset
762 an import library which contains a jump table with an entry for each
kono
parents:
diff changeset
763 routine and variable exported by the DLL. In the Microsoft world this
kono
parents:
diff changeset
764 import library is called :file:`API.lib`. When using GNAT this import
kono
parents:
diff changeset
765 library is called either :file:`libAPI.dll.a`, :file:`libapi.dll.a`,
kono
parents:
diff changeset
766 :file:`libAPI.a` or :file:`libapi.a` (names are case insensitive).
kono
parents:
diff changeset
767
kono
parents:
diff changeset
768 After you have linked your application with the DLL or the import library
kono
parents:
diff changeset
769 and you run your application, here is what happens:
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 * Your application is loaded into memory.
kono
parents:
diff changeset
772
kono
parents:
diff changeset
773 * The DLL :file:`API.dll` is mapped into the address space of your
kono
parents:
diff changeset
774 application. This means that:
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 - The DLL will use the stack of the calling thread.
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 - The DLL will use the virtual address space of the calling process.
kono
parents:
diff changeset
779
kono
parents:
diff changeset
780 - The DLL will allocate memory from the virtual address space of the calling
kono
parents:
diff changeset
781 process.
kono
parents:
diff changeset
782
kono
parents:
diff changeset
783 - Handles (pointers) can be safely exchanged between routines in the DLL
kono
parents:
diff changeset
784 routines and routines in the application using the DLL.
kono
parents:
diff changeset
785
kono
parents:
diff changeset
786 * The entries in the jump table (from the import library :file:`libAPI.dll.a`
kono
parents:
diff changeset
787 or :file:`API.lib` or automatically created when linking against a DLL)
kono
parents:
diff changeset
788 which is part of your application are initialized with the addresses
kono
parents:
diff changeset
789 of the routines and variables in :file:`API.dll`.
kono
parents:
diff changeset
790
kono
parents:
diff changeset
791 * If present in :file:`API.dll`, routines ``DllMain`` or
kono
parents:
diff changeset
792 ``DllMainCRTStartup`` are invoked. These routines typically contain
kono
parents:
diff changeset
793 the initialization code needed for the well-being of the routines and
kono
parents:
diff changeset
794 variables exported by the DLL.
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 There is an additional point which is worth mentioning. In the Windows
kono
parents:
diff changeset
797 world there are two kind of DLLs: relocatable and non-relocatable
kono
parents:
diff changeset
798 DLLs. Non-relocatable DLLs can only be loaded at a very specific address
kono
parents:
diff changeset
799 in the target application address space. If the addresses of two
kono
parents:
diff changeset
800 non-relocatable DLLs overlap and these happen to be used by the same
kono
parents:
diff changeset
801 application, a conflict will occur and the application will run
kono
parents:
diff changeset
802 incorrectly. Hence, when possible, it is always preferable to use and
kono
parents:
diff changeset
803 build relocatable DLLs. Both relocatable and non-relocatable DLLs are
kono
parents:
diff changeset
804 supported by GNAT. Note that the :switch:`-s` linker option (see GNU Linker
kono
parents:
diff changeset
805 User's Guide) removes the debugging symbols from the DLL but the DLL can
kono
parents:
diff changeset
806 still be relocated.
kono
parents:
diff changeset
807
kono
parents:
diff changeset
808 As a side note, an interesting difference between Microsoft DLLs and
kono
parents:
diff changeset
809 Unix shared libraries, is the fact that on most Unix systems all public
kono
parents:
diff changeset
810 routines are exported by default in a Unix shared library, while under
kono
parents:
diff changeset
811 Windows it is possible (but not required) to list exported routines in
kono
parents:
diff changeset
812 a definition file (see :ref:`The Definition File <The_Definition_File>`).
kono
parents:
diff changeset
813
kono
parents:
diff changeset
814
kono
parents:
diff changeset
815 .. _Using_DLLs_with_GNAT:
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 Using DLLs with GNAT
kono
parents:
diff changeset
818 ^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
819
kono
parents:
diff changeset
820 To use the services of a DLL, say :file:`API.dll`, in your Ada application
kono
parents:
diff changeset
821 you must have:
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 * The Ada spec for the routines and/or variables you want to access in
kono
parents:
diff changeset
824 :file:`API.dll`. If not available this Ada spec must be built from the C/C++
kono
parents:
diff changeset
825 header files provided with the DLL.
kono
parents:
diff changeset
826
kono
parents:
diff changeset
827 * The import library (:file:`libAPI.dll.a` or :file:`API.lib`). As previously
kono
parents:
diff changeset
828 mentioned an import library is a statically linked library containing the
kono
parents:
diff changeset
829 import table which will be filled at load time to point to the actual
kono
parents:
diff changeset
830 :file:`API.dll` routines. Sometimes you don't have an import library for the
kono
parents:
diff changeset
831 DLL you want to use. The following sections will explain how to build
kono
parents:
diff changeset
832 one. Note that this is optional.
kono
parents:
diff changeset
833
kono
parents:
diff changeset
834 * The actual DLL, :file:`API.dll`.
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 Once you have all the above, to compile an Ada application that uses the
kono
parents:
diff changeset
837 services of :file:`API.dll` and whose main subprogram is ``My_Ada_App``,
kono
parents:
diff changeset
838 you simply issue the command
kono
parents:
diff changeset
839
kono
parents:
diff changeset
840 ::
kono
parents:
diff changeset
841
kono
parents:
diff changeset
842 $ gnatmake my_ada_app -largs -lAPI
kono
parents:
diff changeset
843
kono
parents:
diff changeset
844 The argument :switch:`-largs -lAPI` at the end of the ``gnatmake`` command
kono
parents:
diff changeset
845 tells the GNAT linker to look for an import library. The linker will
kono
parents:
diff changeset
846 look for a library name in this specific order:
kono
parents:
diff changeset
847
kono
parents:
diff changeset
848 * :file:`libAPI.dll.a`
kono
parents:
diff changeset
849 * :file:`API.dll.a`
kono
parents:
diff changeset
850 * :file:`libAPI.a`
kono
parents:
diff changeset
851 * :file:`API.lib`
kono
parents:
diff changeset
852 * :file:`libAPI.dll`
kono
parents:
diff changeset
853 * :file:`API.dll`
kono
parents:
diff changeset
854
kono
parents:
diff changeset
855 The first three are the GNU style import libraries. The third is the
kono
parents:
diff changeset
856 Microsoft style import libraries. The last two are the actual DLL names.
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 Note that if the Ada package spec for :file:`API.dll` contains the
kono
parents:
diff changeset
859 following pragma
kono
parents:
diff changeset
860
kono
parents:
diff changeset
861 .. code-block:: ada
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 pragma Linker_Options ("-lAPI");
kono
parents:
diff changeset
864
kono
parents:
diff changeset
865 you do not have to add :switch:`-largs -lAPI` at the end of the
kono
parents:
diff changeset
866 ``gnatmake`` command.
kono
parents:
diff changeset
867
kono
parents:
diff changeset
868 If any one of the items above is missing you will have to create it
kono
parents:
diff changeset
869 yourself. The following sections explain how to do so using as an
kono
parents:
diff changeset
870 example a fictitious DLL called :file:`API.dll`.
kono
parents:
diff changeset
871
kono
parents:
diff changeset
872
kono
parents:
diff changeset
873 .. _Creating_an_Ada_Spec_for_the_DLL_Services:
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 Creating an Ada Spec for the DLL Services
kono
parents:
diff changeset
876 """""""""""""""""""""""""""""""""""""""""
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 A DLL typically comes with a C/C++ header file which provides the
kono
parents:
diff changeset
879 definitions of the routines and variables exported by the DLL. The Ada
kono
parents:
diff changeset
880 equivalent of this header file is a package spec that contains definitions
kono
parents:
diff changeset
881 for the imported entities. If the DLL you intend to use does not come with
kono
parents:
diff changeset
882 an Ada spec you have to generate one such spec yourself. For example if
kono
parents:
diff changeset
883 the header file of :file:`API.dll` is a file :file:`api.h` containing the
kono
parents:
diff changeset
884 following two definitions:
kono
parents:
diff changeset
885
kono
parents:
diff changeset
886 .. code-block:: c
kono
parents:
diff changeset
887
kono
parents:
diff changeset
888 int some_var;
kono
parents:
diff changeset
889 int get (char *);
kono
parents:
diff changeset
890
kono
parents:
diff changeset
891 then the equivalent Ada spec could be:
kono
parents:
diff changeset
892
kono
parents:
diff changeset
893 .. code-block:: ada
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 with Interfaces.C.Strings;
kono
parents:
diff changeset
896 package API is
kono
parents:
diff changeset
897 use Interfaces;
kono
parents:
diff changeset
898
kono
parents:
diff changeset
899 Some_Var : C.int;
kono
parents:
diff changeset
900 function Get (Str : C.Strings.Chars_Ptr) return C.int;
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 private
kono
parents:
diff changeset
903 pragma Import (C, Get);
kono
parents:
diff changeset
904 pragma Import (DLL, Some_Var);
kono
parents:
diff changeset
905 end API;
kono
parents:
diff changeset
906
kono
parents:
diff changeset
907
kono
parents:
diff changeset
908 .. _Creating_an_Import_Library:
kono
parents:
diff changeset
909
kono
parents:
diff changeset
910 Creating an Import Library
kono
parents:
diff changeset
911 """"""""""""""""""""""""""
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 .. index:: Import library
kono
parents:
diff changeset
914
kono
parents:
diff changeset
915 If a Microsoft-style import library :file:`API.lib` or a GNAT-style
kono
parents:
diff changeset
916 import library :file:`libAPI.dll.a` or :file:`libAPI.a` is available
kono
parents:
diff changeset
917 with :file:`API.dll` you can skip this section. You can also skip this
kono
parents:
diff changeset
918 section if :file:`API.dll` or :file:`libAPI.dll` is built with GNU tools
kono
parents:
diff changeset
919 as in this case it is possible to link directly against the
kono
parents:
diff changeset
920 DLL. Otherwise read on.
kono
parents:
diff changeset
921
kono
parents:
diff changeset
922
kono
parents:
diff changeset
923 .. index:: Definition file
kono
parents:
diff changeset
924
kono
parents:
diff changeset
925 .. _The_Definition_File:
kono
parents:
diff changeset
926
kono
parents:
diff changeset
927 .. rubric:: The Definition File
kono
parents:
diff changeset
928
kono
parents:
diff changeset
929 As previously mentioned, and unlike Unix systems, the list of symbols
kono
parents:
diff changeset
930 that are exported from a DLL must be provided explicitly in Windows.
kono
parents:
diff changeset
931 The main goal of a definition file is precisely that: list the symbols
kono
parents:
diff changeset
932 exported by a DLL. A definition file (usually a file with a ``.def``
kono
parents:
diff changeset
933 suffix) has the following structure:
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 ::
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 [LIBRARY ``name``]
kono
parents:
diff changeset
938 [DESCRIPTION ``string``]
kono
parents:
diff changeset
939 EXPORTS
kono
parents:
diff changeset
940 ``symbol1``
kono
parents:
diff changeset
941 ``symbol2``
kono
parents:
diff changeset
942 ...
kono
parents:
diff changeset
943
kono
parents:
diff changeset
944 *LIBRARY name*
kono
parents:
diff changeset
945 This section, which is optional, gives the name of the DLL.
kono
parents:
diff changeset
946
kono
parents:
diff changeset
947
kono
parents:
diff changeset
948 *DESCRIPTION string*
kono
parents:
diff changeset
949 This section, which is optional, gives a description string that will be
kono
parents:
diff changeset
950 embedded in the import library.
kono
parents:
diff changeset
951
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 *EXPORTS*
kono
parents:
diff changeset
954 This section gives the list of exported symbols (procedures, functions or
kono
parents:
diff changeset
955 variables). For instance in the case of :file:`API.dll` the ``EXPORTS``
kono
parents:
diff changeset
956 section of :file:`API.def` looks like:
kono
parents:
diff changeset
957
kono
parents:
diff changeset
958 ::
kono
parents:
diff changeset
959
kono
parents:
diff changeset
960 EXPORTS
kono
parents:
diff changeset
961 some_var
kono
parents:
diff changeset
962 get
kono
parents:
diff changeset
963
kono
parents:
diff changeset
964 Note that you must specify the correct suffix (:samp:`@{nn}`)
kono
parents:
diff changeset
965 (see :ref:`Windows_Calling_Conventions`) for a Stdcall
kono
parents:
diff changeset
966 calling convention function in the exported symbols list.
kono
parents:
diff changeset
967
kono
parents:
diff changeset
968 There can actually be other sections in a definition file, but these
kono
parents:
diff changeset
969 sections are not relevant to the discussion at hand.
kono
parents:
diff changeset
970
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 .. _Create_Def_File_Automatically:
kono
parents:
diff changeset
973
kono
parents:
diff changeset
974 .. rubric:: Creating a Definition File Automatically
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 You can automatically create the definition file :file:`API.def`
kono
parents:
diff changeset
977 (see :ref:`The Definition File <The_Definition_File>`) from a DLL.
kono
parents:
diff changeset
978 For that use the ``dlltool`` program as follows:
kono
parents:
diff changeset
979
kono
parents:
diff changeset
980 ::
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 $ dlltool API.dll -z API.def --export-all-symbols
kono
parents:
diff changeset
983
kono
parents:
diff changeset
984 Note that if some routines in the DLL have the ``Stdcall`` convention
kono
parents:
diff changeset
985 (:ref:`Windows_Calling_Conventions`) with stripped :samp:`@{nn}`
kono
parents:
diff changeset
986 suffix then you'll have to edit :file:`api.def` to add it, and specify
kono
parents:
diff changeset
987 :switch:`-k` to ``gnatdll`` when creating the import library.
kono
parents:
diff changeset
988
kono
parents:
diff changeset
989 Here are some hints to find the right :samp:`@{nn}` suffix.
kono
parents:
diff changeset
990
kono
parents:
diff changeset
991 - If you have the Microsoft import library (.lib), it is possible to get
kono
parents:
diff changeset
992 the right symbols by using Microsoft ``dumpbin`` tool (see the
kono
parents:
diff changeset
993 corresponding Microsoft documentation for further details).
kono
parents:
diff changeset
994
kono
parents:
diff changeset
995 ::
kono
parents:
diff changeset
996
kono
parents:
diff changeset
997 $ dumpbin /exports api.lib
kono
parents:
diff changeset
998
kono
parents:
diff changeset
999 - If you have a message about a missing symbol at link time the compiler
kono
parents:
diff changeset
1000 tells you what symbol is expected. You just have to go back to the
kono
parents:
diff changeset
1001 definition file and add the right suffix.
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003
kono
parents:
diff changeset
1004 .. _GNAT-Style_Import_Library:
kono
parents:
diff changeset
1005
kono
parents:
diff changeset
1006 .. rubric:: GNAT-Style Import Library
kono
parents:
diff changeset
1007
kono
parents:
diff changeset
1008 To create a static import library from :file:`API.dll` with the GNAT tools
kono
parents:
diff changeset
1009 you should create the .def file, then use ``gnatdll`` tool
kono
parents:
diff changeset
1010 (see :ref:`Using_gnatdll`) as follows:
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 ::
kono
parents:
diff changeset
1013
kono
parents:
diff changeset
1014 $ gnatdll -e API.def -d API.dll
kono
parents:
diff changeset
1015
kono
parents:
diff changeset
1016 ``gnatdll`` takes as input a definition file :file:`API.def` and the
kono
parents:
diff changeset
1017 name of the DLL containing the services listed in the definition file
kono
parents:
diff changeset
1018 :file:`API.dll`. The name of the static import library generated is
kono
parents:
diff changeset
1019 computed from the name of the definition file as follows: if the
kono
parents:
diff changeset
1020 definition file name is :file:`xyz.def`, the import library name will
kono
parents:
diff changeset
1021 be :file:`libxyz.a`. Note that in the previous example option
kono
parents:
diff changeset
1022 :switch:`-e` could have been removed because the name of the definition
kono
parents:
diff changeset
1023 file (before the ``.def`` suffix) is the same as the name of the
kono
parents:
diff changeset
1024 DLL (:ref:`Using_gnatdll` for more information about ``gnatdll``).
kono
parents:
diff changeset
1025
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 .. _MSVS-Style_Import_Library:
kono
parents:
diff changeset
1028
kono
parents:
diff changeset
1029 .. rubric:: Microsoft-Style Import Library
kono
parents:
diff changeset
1030
kono
parents:
diff changeset
1031 A Microsoft import library is needed only if you plan to make an
kono
parents:
diff changeset
1032 Ada DLL available to applications developed with Microsoft
kono
parents:
diff changeset
1033 tools (:ref:`Mixed-Language_Programming_on_Windows`).
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 To create a Microsoft-style import library for :file:`API.dll` you
kono
parents:
diff changeset
1036 should create the .def file, then build the actual import library using
kono
parents:
diff changeset
1037 Microsoft's ``lib`` utility:
kono
parents:
diff changeset
1038
kono
parents:
diff changeset
1039 ::
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 $ lib -machine:IX86 -def:API.def -out:API.lib
kono
parents:
diff changeset
1042
kono
parents:
diff changeset
1043 If you use the above command the definition file :file:`API.def` must
kono
parents:
diff changeset
1044 contain a line giving the name of the DLL:
kono
parents:
diff changeset
1045
kono
parents:
diff changeset
1046 ::
kono
parents:
diff changeset
1047
kono
parents:
diff changeset
1048 LIBRARY "API"
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 See the Microsoft documentation for further details about the usage of
kono
parents:
diff changeset
1051 ``lib``.
kono
parents:
diff changeset
1052
kono
parents:
diff changeset
1053
kono
parents:
diff changeset
1054 .. _Building_DLLs_with_GNAT_Project_files:
kono
parents:
diff changeset
1055
kono
parents:
diff changeset
1056 Building DLLs with GNAT Project files
kono
parents:
diff changeset
1057 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1058
kono
parents:
diff changeset
1059 .. index:: DLLs, building
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 There is nothing specific to Windows in the build process.
kono
parents:
diff changeset
1062 See the *Library Projects* section in the *GNAT Project Manager*
kono
parents:
diff changeset
1063 chapter of the *GPRbuild User's Guide*.
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 Due to a system limitation, it is not possible under Windows to create threads
kono
parents:
diff changeset
1066 when inside the ``DllMain`` routine which is used for auto-initialization
kono
parents:
diff changeset
1067 of shared libraries, so it is not possible to have library level tasks in SALs.
kono
parents:
diff changeset
1068
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 .. _Building_DLLs_with_GNAT:
kono
parents:
diff changeset
1071
kono
parents:
diff changeset
1072 Building DLLs with GNAT
kono
parents:
diff changeset
1073 ^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1074
kono
parents:
diff changeset
1075 .. index:: DLLs, building
kono
parents:
diff changeset
1076
kono
parents:
diff changeset
1077 This section explain how to build DLLs using the GNAT built-in DLL
kono
parents:
diff changeset
1078 support. With the following procedure it is straight forward to build
kono
parents:
diff changeset
1079 and use DLLs with GNAT.
kono
parents:
diff changeset
1080
kono
parents:
diff changeset
1081
kono
parents:
diff changeset
1082 * Building object files.
kono
parents:
diff changeset
1083 The first step is to build all objects files that are to be included
kono
parents:
diff changeset
1084 into the DLL. This is done by using the standard ``gnatmake`` tool.
kono
parents:
diff changeset
1085
kono
parents:
diff changeset
1086 * Building the DLL.
kono
parents:
diff changeset
1087 To build the DLL you must use the ``gcc`` :switch:`-shared` and
kono
parents:
diff changeset
1088 :switch:`-shared-libgcc` options. It is quite simple to use this method:
kono
parents:
diff changeset
1089
kono
parents:
diff changeset
1090 ::
kono
parents:
diff changeset
1091
kono
parents:
diff changeset
1092 $ gcc -shared -shared-libgcc -o api.dll obj1.o obj2.o ...
kono
parents:
diff changeset
1093
kono
parents:
diff changeset
1094 It is important to note that in this case all symbols found in the
kono
parents:
diff changeset
1095 object files are automatically exported. It is possible to restrict
kono
parents:
diff changeset
1096 the set of symbols to export by passing to ``gcc`` a definition
kono
parents:
diff changeset
1097 file (see :ref:`The Definition File <The_Definition_File>`).
kono
parents:
diff changeset
1098 For example:
kono
parents:
diff changeset
1099
kono
parents:
diff changeset
1100 ::
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 $ gcc -shared -shared-libgcc -o api.dll api.def obj1.o obj2.o ...
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 If you use a definition file you must export the elaboration procedures
kono
parents:
diff changeset
1105 for every package that required one. Elaboration procedures are named
kono
parents:
diff changeset
1106 using the package name followed by "_E".
kono
parents:
diff changeset
1107
kono
parents:
diff changeset
1108 * Preparing DLL to be used.
kono
parents:
diff changeset
1109 For the DLL to be used by client programs the bodies must be hidden
kono
parents:
diff changeset
1110 from it and the .ali set with read-only attribute. This is very important
kono
parents:
diff changeset
1111 otherwise GNAT will recompile all packages and will not actually use
kono
parents:
diff changeset
1112 the code in the DLL. For example:
kono
parents:
diff changeset
1113
kono
parents:
diff changeset
1114 ::
kono
parents:
diff changeset
1115
kono
parents:
diff changeset
1116 $ mkdir apilib
kono
parents:
diff changeset
1117 $ copy *.ads *.ali api.dll apilib
kono
parents:
diff changeset
1118 $ attrib +R apilib\\*.ali
kono
parents:
diff changeset
1119
kono
parents:
diff changeset
1120 At this point it is possible to use the DLL by directly linking
kono
parents:
diff changeset
1121 against it. Note that you must use the GNAT shared runtime when using
kono
parents:
diff changeset
1122 GNAT shared libraries. This is achieved by using the :switch:`-shared` binder
kono
parents:
diff changeset
1123 option.
kono
parents:
diff changeset
1124
kono
parents:
diff changeset
1125 ::
kono
parents:
diff changeset
1126
kono
parents:
diff changeset
1127 $ gnatmake main -Iapilib -bargs -shared -largs -Lapilib -lAPI
kono
parents:
diff changeset
1128
kono
parents:
diff changeset
1129
kono
parents:
diff changeset
1130 .. _Building_DLLs_with_gnatdll:
kono
parents:
diff changeset
1131
kono
parents:
diff changeset
1132 Building DLLs with gnatdll
kono
parents:
diff changeset
1133 ^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1134
kono
parents:
diff changeset
1135 .. index:: DLLs, building
kono
parents:
diff changeset
1136
kono
parents:
diff changeset
1137 Note that it is preferred to use GNAT Project files
kono
parents:
diff changeset
1138 (:ref:`Building_DLLs_with_GNAT_Project_files`) or the built-in GNAT
kono
parents:
diff changeset
1139 DLL support (:ref:`Building_DLLs_with_GNAT`) or to build DLLs.
kono
parents:
diff changeset
1140
kono
parents:
diff changeset
1141 This section explains how to build DLLs containing Ada code using
kono
parents:
diff changeset
1142 ``gnatdll``. These DLLs will be referred to as Ada DLLs in the
kono
parents:
diff changeset
1143 remainder of this section.
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 The steps required to build an Ada DLL that is to be used by Ada as well as
kono
parents:
diff changeset
1146 non-Ada applications are as follows:
kono
parents:
diff changeset
1147
kono
parents:
diff changeset
1148 * You need to mark each Ada entity exported by the DLL with a ``C`` or
kono
parents:
diff changeset
1149 ``Stdcall`` calling convention to avoid any Ada name mangling for the
kono
parents:
diff changeset
1150 entities exported by the DLL
kono
parents:
diff changeset
1151 (see :ref:`Exporting Ada Entities <Exporting_Ada_Entities>`). You can
kono
parents:
diff changeset
1152 skip this step if you plan to use the Ada DLL only from Ada applications.
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 * Your Ada code must export an initialization routine which calls the routine
kono
parents:
diff changeset
1155 ``adainit`` generated by ``gnatbind`` to perform the elaboration of
kono
parents:
diff changeset
1156 the Ada code in the DLL (:ref:`Ada_DLLs_and_Elaboration`). The initialization
kono
parents:
diff changeset
1157 routine exported by the Ada DLL must be invoked by the clients of the DLL
kono
parents:
diff changeset
1158 to initialize the DLL.
kono
parents:
diff changeset
1159
kono
parents:
diff changeset
1160 * When useful, the DLL should also export a finalization routine which calls
kono
parents:
diff changeset
1161 routine ``adafinal`` generated by ``gnatbind`` to perform the
kono
parents:
diff changeset
1162 finalization of the Ada code in the DLL (:ref:`Ada_DLLs_and_Finalization`).
kono
parents:
diff changeset
1163 The finalization routine exported by the Ada DLL must be invoked by the
kono
parents:
diff changeset
1164 clients of the DLL when the DLL services are no further needed.
kono
parents:
diff changeset
1165
kono
parents:
diff changeset
1166 * You must provide a spec for the services exported by the Ada DLL in each
kono
parents:
diff changeset
1167 of the programming languages to which you plan to make the DLL available.
kono
parents:
diff changeset
1168
kono
parents:
diff changeset
1169 * You must provide a definition file listing the exported entities
kono
parents:
diff changeset
1170 (:ref:`The Definition File <The_Definition_File>`).
kono
parents:
diff changeset
1171
kono
parents:
diff changeset
1172 * Finally you must use ``gnatdll`` to produce the DLL and the import
kono
parents:
diff changeset
1173 library (:ref:`Using_gnatdll`).
kono
parents:
diff changeset
1174
kono
parents:
diff changeset
1175 Note that a relocatable DLL stripped using the ``strip``
kono
parents:
diff changeset
1176 binutils tool will not be relocatable anymore. To build a DLL without
kono
parents:
diff changeset
1177 debug information pass :switch:`-largs -s` to ``gnatdll``. This
kono
parents:
diff changeset
1178 restriction does not apply to a DLL built using a Library Project.
kono
parents:
diff changeset
1179 See the *Library Projects* section in the *GNAT Project Manager*
kono
parents:
diff changeset
1180 chapter of the *GPRbuild User's Guide*.
kono
parents:
diff changeset
1181
kono
parents:
diff changeset
1182
kono
parents:
diff changeset
1183 .. Limitations_When_Using_Ada_DLLs_from Ada:
kono
parents:
diff changeset
1184
kono
parents:
diff changeset
1185 Limitations When Using Ada DLLs from Ada
kono
parents:
diff changeset
1186 """"""""""""""""""""""""""""""""""""""""
kono
parents:
diff changeset
1187
kono
parents:
diff changeset
1188 When using Ada DLLs from Ada applications there is a limitation users
kono
parents:
diff changeset
1189 should be aware of. Because on Windows the GNAT run-time is not in a DLL of
kono
parents:
diff changeset
1190 its own, each Ada DLL includes a part of the GNAT run-time. Specifically,
kono
parents:
diff changeset
1191 each Ada DLL includes the services of the GNAT run-time that are necessary
kono
parents:
diff changeset
1192 to the Ada code inside the DLL. As a result, when an Ada program uses an
kono
parents:
diff changeset
1193 Ada DLL there are two independent GNAT run-times: one in the Ada DLL and
kono
parents:
diff changeset
1194 one in the main program.
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 It is therefore not possible to exchange GNAT run-time objects between the
kono
parents:
diff changeset
1197 Ada DLL and the main Ada program. Example of GNAT run-time objects are file
kono
parents:
diff changeset
1198 handles (e.g., ``Text_IO.File_Type``), tasks types, protected objects
kono
parents:
diff changeset
1199 types, etc.
kono
parents:
diff changeset
1200
kono
parents:
diff changeset
1201 It is completely safe to exchange plain elementary, array or record types,
kono
parents:
diff changeset
1202 Windows object handles, etc.
kono
parents:
diff changeset
1203
kono
parents:
diff changeset
1204
kono
parents:
diff changeset
1205 .. _Exporting_Ada_Entities:
kono
parents:
diff changeset
1206
kono
parents:
diff changeset
1207 Exporting Ada Entities
kono
parents:
diff changeset
1208 """"""""""""""""""""""
kono
parents:
diff changeset
1209
kono
parents:
diff changeset
1210 .. index:: Export table
kono
parents:
diff changeset
1211
kono
parents:
diff changeset
1212 Building a DLL is a way to encapsulate a set of services usable from any
kono
parents:
diff changeset
1213 application. As a result, the Ada entities exported by a DLL should be
kono
parents:
diff changeset
1214 exported with the ``C`` or ``Stdcall`` calling conventions to avoid
kono
parents:
diff changeset
1215 any Ada name mangling. As an example here is an Ada package
kono
parents:
diff changeset
1216 ``API``, spec and body, exporting two procedures, a function, and a
kono
parents:
diff changeset
1217 variable:
kono
parents:
diff changeset
1218
kono
parents:
diff changeset
1219
kono
parents:
diff changeset
1220 .. code-block:: ada
kono
parents:
diff changeset
1221
kono
parents:
diff changeset
1222 with Interfaces.C; use Interfaces;
kono
parents:
diff changeset
1223 package API is
kono
parents:
diff changeset
1224 Count : C.int := 0;
kono
parents:
diff changeset
1225 function Factorial (Val : C.int) return C.int;
kono
parents:
diff changeset
1226
kono
parents:
diff changeset
1227 procedure Initialize_API;
kono
parents:
diff changeset
1228 procedure Finalize_API;
kono
parents:
diff changeset
1229 -- Initialization & Finalization routines. More in the next section.
kono
parents:
diff changeset
1230 private
kono
parents:
diff changeset
1231 pragma Export (C, Initialize_API);
kono
parents:
diff changeset
1232 pragma Export (C, Finalize_API);
kono
parents:
diff changeset
1233 pragma Export (C, Count);
kono
parents:
diff changeset
1234 pragma Export (C, Factorial);
kono
parents:
diff changeset
1235 end API;
kono
parents:
diff changeset
1236
kono
parents:
diff changeset
1237 .. code-block:: ada
kono
parents:
diff changeset
1238
kono
parents:
diff changeset
1239 package body API is
kono
parents:
diff changeset
1240 function Factorial (Val : C.int) return C.int is
kono
parents:
diff changeset
1241 Fact : C.int := 1;
kono
parents:
diff changeset
1242 begin
kono
parents:
diff changeset
1243 Count := Count + 1;
kono
parents:
diff changeset
1244 for K in 1 .. Val loop
kono
parents:
diff changeset
1245 Fact := Fact * K;
kono
parents:
diff changeset
1246 end loop;
kono
parents:
diff changeset
1247 return Fact;
kono
parents:
diff changeset
1248 end Factorial;
kono
parents:
diff changeset
1249
kono
parents:
diff changeset
1250 procedure Initialize_API is
kono
parents:
diff changeset
1251 procedure Adainit;
kono
parents:
diff changeset
1252 pragma Import (C, Adainit);
kono
parents:
diff changeset
1253 begin
kono
parents:
diff changeset
1254 Adainit;
kono
parents:
diff changeset
1255 end Initialize_API;
kono
parents:
diff changeset
1256
kono
parents:
diff changeset
1257 procedure Finalize_API is
kono
parents:
diff changeset
1258 procedure Adafinal;
kono
parents:
diff changeset
1259 pragma Import (C, Adafinal);
kono
parents:
diff changeset
1260 begin
kono
parents:
diff changeset
1261 Adafinal;
kono
parents:
diff changeset
1262 end Finalize_API;
kono
parents:
diff changeset
1263 end API;
kono
parents:
diff changeset
1264
kono
parents:
diff changeset
1265 If the Ada DLL you are building will only be used by Ada applications
kono
parents:
diff changeset
1266 you do not have to export Ada entities with a ``C`` or ``Stdcall``
kono
parents:
diff changeset
1267 convention. As an example, the previous package could be written as
kono
parents:
diff changeset
1268 follows:
kono
parents:
diff changeset
1269
kono
parents:
diff changeset
1270 .. code-block:: ada
kono
parents:
diff changeset
1271
kono
parents:
diff changeset
1272 package API is
kono
parents:
diff changeset
1273 Count : Integer := 0;
kono
parents:
diff changeset
1274 function Factorial (Val : Integer) return Integer;
kono
parents:
diff changeset
1275
kono
parents:
diff changeset
1276 procedure Initialize_API;
kono
parents:
diff changeset
1277 procedure Finalize_API;
kono
parents:
diff changeset
1278 -- Initialization and Finalization routines.
kono
parents:
diff changeset
1279 end API;
kono
parents:
diff changeset
1280
kono
parents:
diff changeset
1281 .. code-block:: ada
kono
parents:
diff changeset
1282
kono
parents:
diff changeset
1283 package body API is
kono
parents:
diff changeset
1284 function Factorial (Val : Integer) return Integer is
kono
parents:
diff changeset
1285 Fact : Integer := 1;
kono
parents:
diff changeset
1286 begin
kono
parents:
diff changeset
1287 Count := Count + 1;
kono
parents:
diff changeset
1288 for K in 1 .. Val loop
kono
parents:
diff changeset
1289 Fact := Fact * K;
kono
parents:
diff changeset
1290 end loop;
kono
parents:
diff changeset
1291 return Fact;
kono
parents:
diff changeset
1292 end Factorial;
kono
parents:
diff changeset
1293
kono
parents:
diff changeset
1294 ...
kono
parents:
diff changeset
1295 -- The remainder of this package body is unchanged.
kono
parents:
diff changeset
1296 end API;
kono
parents:
diff changeset
1297
kono
parents:
diff changeset
1298 Note that if you do not export the Ada entities with a ``C`` or
kono
parents:
diff changeset
1299 ``Stdcall`` convention you will have to provide the mangled Ada names
kono
parents:
diff changeset
1300 in the definition file of the Ada DLL
kono
parents:
diff changeset
1301 (:ref:`Creating_the_Definition_File`).
kono
parents:
diff changeset
1302
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 .. _Ada_DLLs_and_Elaboration:
kono
parents:
diff changeset
1305
kono
parents:
diff changeset
1306 Ada DLLs and Elaboration
kono
parents:
diff changeset
1307 """"""""""""""""""""""""
kono
parents:
diff changeset
1308
kono
parents:
diff changeset
1309 .. index:: DLLs and elaboration
kono
parents:
diff changeset
1310
kono
parents:
diff changeset
1311 The DLL that you are building contains your Ada code as well as all the
kono
parents:
diff changeset
1312 routines in the Ada library that are needed by it. The first thing a
kono
parents:
diff changeset
1313 user of your DLL must do is elaborate the Ada code
kono
parents:
diff changeset
1314 (:ref:`Elaboration_Order_Handling_in_GNAT`).
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 To achieve this you must export an initialization routine
kono
parents:
diff changeset
1317 (``Initialize_API`` in the previous example), which must be invoked
kono
parents:
diff changeset
1318 before using any of the DLL services. This elaboration routine must call
kono
parents:
diff changeset
1319 the Ada elaboration routine ``adainit`` generated by the GNAT binder
kono
parents:
diff changeset
1320 (:ref:`Binding_with_Non-Ada_Main_Programs`). See the body of
kono
parents:
diff changeset
1321 ``Initialize_Api`` for an example. Note that the GNAT binder is
kono
parents:
diff changeset
1322 automatically invoked during the DLL build process by the ``gnatdll``
kono
parents:
diff changeset
1323 tool (:ref:`Using_gnatdll`).
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 When a DLL is loaded, Windows systematically invokes a routine called
kono
parents:
diff changeset
1326 ``DllMain``. It would therefore be possible to call ``adainit``
kono
parents:
diff changeset
1327 directly from ``DllMain`` without having to provide an explicit
kono
parents:
diff changeset
1328 initialization routine. Unfortunately, it is not possible to call
kono
parents:
diff changeset
1329 ``adainit`` from the ``DllMain`` if your program has library level
kono
parents:
diff changeset
1330 tasks because access to the ``DllMain`` entry point is serialized by
kono
parents:
diff changeset
1331 the system (that is, only a single thread can execute 'through' it at a
kono
parents:
diff changeset
1332 time), which means that the GNAT run-time will deadlock waiting for the
kono
parents:
diff changeset
1333 newly created task to complete its initialization.
kono
parents:
diff changeset
1334
kono
parents:
diff changeset
1335
kono
parents:
diff changeset
1336 .. _Ada_DLLs_and_Finalization:
kono
parents:
diff changeset
1337
kono
parents:
diff changeset
1338 Ada DLLs and Finalization
kono
parents:
diff changeset
1339 ^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1340
kono
parents:
diff changeset
1341 .. index:: DLLs and finalization
kono
parents:
diff changeset
1342
kono
parents:
diff changeset
1343 When the services of an Ada DLL are no longer needed, the client code should
kono
parents:
diff changeset
1344 invoke the DLL finalization routine, if available. The DLL finalization
kono
parents:
diff changeset
1345 routine is in charge of releasing all resources acquired by the DLL. In the
kono
parents:
diff changeset
1346 case of the Ada code contained in the DLL, this is achieved by calling
kono
parents:
diff changeset
1347 routine ``adafinal`` generated by the GNAT binder
kono
parents:
diff changeset
1348 (:ref:`Binding_with_Non-Ada_Main_Programs`).
kono
parents:
diff changeset
1349 See the body of ``Finalize_Api`` for an
kono
parents:
diff changeset
1350 example. As already pointed out the GNAT binder is automatically invoked
kono
parents:
diff changeset
1351 during the DLL build process by the ``gnatdll`` tool
kono
parents:
diff changeset
1352 (:ref:`Using_gnatdll`).
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354
kono
parents:
diff changeset
1355 .. _Creating_a_Spec_for_Ada_DLLs:
kono
parents:
diff changeset
1356
kono
parents:
diff changeset
1357 Creating a Spec for Ada DLLs
kono
parents:
diff changeset
1358 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1359
kono
parents:
diff changeset
1360 To use the services exported by the Ada DLL from another programming
kono
parents:
diff changeset
1361 language (e.g., C), you have to translate the specs of the exported Ada
kono
parents:
diff changeset
1362 entities in that language. For instance in the case of ``API.dll``,
kono
parents:
diff changeset
1363 the corresponding C header file could look like:
kono
parents:
diff changeset
1364
kono
parents:
diff changeset
1365 .. code-block:: c
kono
parents:
diff changeset
1366
kono
parents:
diff changeset
1367 extern int *_imp__count;
kono
parents:
diff changeset
1368 #define count (*_imp__count)
kono
parents:
diff changeset
1369 int factorial (int);
kono
parents:
diff changeset
1370
kono
parents:
diff changeset
1371 It is important to understand that when building an Ada DLL to be used by
kono
parents:
diff changeset
1372 other Ada applications, you need two different specs for the packages
kono
parents:
diff changeset
1373 contained in the DLL: one for building the DLL and the other for using
kono
parents:
diff changeset
1374 the DLL. This is because the ``DLL`` calling convention is needed to
kono
parents:
diff changeset
1375 use a variable defined in a DLL, but when building the DLL, the variable
kono
parents:
diff changeset
1376 must have either the ``Ada`` or ``C`` calling convention. As an
kono
parents:
diff changeset
1377 example consider a DLL comprising the following package ``API``:
kono
parents:
diff changeset
1378
kono
parents:
diff changeset
1379 .. code-block:: ada
kono
parents:
diff changeset
1380
kono
parents:
diff changeset
1381 package API is
kono
parents:
diff changeset
1382 Count : Integer := 0;
kono
parents:
diff changeset
1383 ...
kono
parents:
diff changeset
1384 -- Remainder of the package omitted.
kono
parents:
diff changeset
1385 end API;
kono
parents:
diff changeset
1386
kono
parents:
diff changeset
1387 After producing a DLL containing package ``API``, the spec that
kono
parents:
diff changeset
1388 must be used to import ``API.Count`` from Ada code outside of the
kono
parents:
diff changeset
1389 DLL is:
kono
parents:
diff changeset
1390
kono
parents:
diff changeset
1391 .. code-block:: ada
kono
parents:
diff changeset
1392
kono
parents:
diff changeset
1393 package API is
kono
parents:
diff changeset
1394 Count : Integer;
kono
parents:
diff changeset
1395 pragma Import (DLL, Count);
kono
parents:
diff changeset
1396 end API;
kono
parents:
diff changeset
1397
kono
parents:
diff changeset
1398
kono
parents:
diff changeset
1399 .. _Creating_the_Definition_File:
kono
parents:
diff changeset
1400
kono
parents:
diff changeset
1401 Creating the Definition File
kono
parents:
diff changeset
1402 """"""""""""""""""""""""""""
kono
parents:
diff changeset
1403
kono
parents:
diff changeset
1404 The definition file is the last file needed to build the DLL. It lists
kono
parents:
diff changeset
1405 the exported symbols. As an example, the definition file for a DLL
kono
parents:
diff changeset
1406 containing only package ``API`` (where all the entities are exported
kono
parents:
diff changeset
1407 with a ``C`` calling convention) is:
kono
parents:
diff changeset
1408
kono
parents:
diff changeset
1409 ::
kono
parents:
diff changeset
1410
kono
parents:
diff changeset
1411 EXPORTS
kono
parents:
diff changeset
1412 count
kono
parents:
diff changeset
1413 factorial
kono
parents:
diff changeset
1414 finalize_api
kono
parents:
diff changeset
1415 initialize_api
kono
parents:
diff changeset
1416
kono
parents:
diff changeset
1417 If the ``C`` calling convention is missing from package ``API``,
kono
parents:
diff changeset
1418 then the definition file contains the mangled Ada names of the above
kono
parents:
diff changeset
1419 entities, which in this case are:
kono
parents:
diff changeset
1420
kono
parents:
diff changeset
1421 ::
kono
parents:
diff changeset
1422
kono
parents:
diff changeset
1423 EXPORTS
kono
parents:
diff changeset
1424 api__count
kono
parents:
diff changeset
1425 api__factorial
kono
parents:
diff changeset
1426 api__finalize_api
kono
parents:
diff changeset
1427 api__initialize_api
kono
parents:
diff changeset
1428
kono
parents:
diff changeset
1429
kono
parents:
diff changeset
1430 .. _Using_gnatdll:
kono
parents:
diff changeset
1431
kono
parents:
diff changeset
1432 Using ``gnatdll``
kono
parents:
diff changeset
1433 """""""""""""""""
kono
parents:
diff changeset
1434
kono
parents:
diff changeset
1435 .. index:: gnatdll
kono
parents:
diff changeset
1436
kono
parents:
diff changeset
1437 ``gnatdll`` is a tool to automate the DLL build process once all the Ada
kono
parents:
diff changeset
1438 and non-Ada sources that make up your DLL have been compiled.
kono
parents:
diff changeset
1439 ``gnatdll`` is actually in charge of two distinct tasks: build the
kono
parents:
diff changeset
1440 static import library for the DLL and the actual DLL. The form of the
kono
parents:
diff changeset
1441 ``gnatdll`` command is
kono
parents:
diff changeset
1442
kono
parents:
diff changeset
1443 ::
kono
parents:
diff changeset
1444
kono
parents:
diff changeset
1445 $ gnatdll [ switches ] list-of-files [ -largs opts ]
kono
parents:
diff changeset
1446
kono
parents:
diff changeset
1447 where ``list-of-files`` is a list of ALI and object files. The object
kono
parents:
diff changeset
1448 file list must be the exact list of objects corresponding to the non-Ada
kono
parents:
diff changeset
1449 sources whose services are to be included in the DLL. The ALI file list
kono
parents:
diff changeset
1450 must be the exact list of ALI files for the corresponding Ada sources
kono
parents:
diff changeset
1451 whose services are to be included in the DLL. If ``list-of-files`` is
kono
parents:
diff changeset
1452 missing, only the static import library is generated.
kono
parents:
diff changeset
1453
kono
parents:
diff changeset
1454 You may specify any of the following switches to ``gnatdll``:
kono
parents:
diff changeset
1455
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 .. index:: -a (gnatdll)
kono
parents:
diff changeset
1458
kono
parents:
diff changeset
1459 :switch:`-a[{address}]`
kono
parents:
diff changeset
1460 Build a non-relocatable DLL at ``address``. If ``address`` is not
kono
parents:
diff changeset
1461 specified the default address ``0x11000000`` will be used. By default,
kono
parents:
diff changeset
1462 when this switch is missing, ``gnatdll`` builds relocatable DLL. We
kono
parents:
diff changeset
1463 advise the reader to build relocatable DLL.
kono
parents:
diff changeset
1464
kono
parents:
diff changeset
1465
kono
parents:
diff changeset
1466 .. index:: -b (gnatdll)
kono
parents:
diff changeset
1467
kono
parents:
diff changeset
1468 :switch:`-b {address}`
kono
parents:
diff changeset
1469 Set the relocatable DLL base address. By default the address is
kono
parents:
diff changeset
1470 ``0x11000000``.
kono
parents:
diff changeset
1471
kono
parents:
diff changeset
1472
kono
parents:
diff changeset
1473 .. index:: -bargs (gnatdll)
kono
parents:
diff changeset
1474
kono
parents:
diff changeset
1475 :switch:`-bargs {opts}`
kono
parents:
diff changeset
1476 Binder options. Pass ``opts`` to the binder.
kono
parents:
diff changeset
1477
kono
parents:
diff changeset
1478
kono
parents:
diff changeset
1479 .. index:: -d (gnatdll)
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 :switch:`-d {dllfile}`
kono
parents:
diff changeset
1482 ``dllfile`` is the name of the DLL. This switch must be present for
kono
parents:
diff changeset
1483 ``gnatdll`` to do anything. The name of the generated import library is
kono
parents:
diff changeset
1484 obtained algorithmically from ``dllfile`` as shown in the following
kono
parents:
diff changeset
1485 example: if ``dllfile`` is :file:`xyz.dll`, the import library name is
kono
parents:
diff changeset
1486 :file:`libxyz.dll.a`. The name of the definition file to use (if not specified
kono
parents:
diff changeset
1487 by option :switch:`-e`) is obtained algorithmically from ``dllfile``
kono
parents:
diff changeset
1488 as shown in the following example:
kono
parents:
diff changeset
1489 if ``dllfile`` is :file:`xyz.dll`, the definition
kono
parents:
diff changeset
1490 file used is :file:`xyz.def`.
kono
parents:
diff changeset
1491
kono
parents:
diff changeset
1492
kono
parents:
diff changeset
1493 .. index:: -e (gnatdll)
kono
parents:
diff changeset
1494
kono
parents:
diff changeset
1495 :switch:`-e {deffile}`
kono
parents:
diff changeset
1496 ``deffile`` is the name of the definition file.
kono
parents:
diff changeset
1497
kono
parents:
diff changeset
1498
kono
parents:
diff changeset
1499 .. index:: -g (gnatdll)
kono
parents:
diff changeset
1500
kono
parents:
diff changeset
1501 :switch:`-g`
kono
parents:
diff changeset
1502 Generate debugging information. This information is stored in the object
kono
parents:
diff changeset
1503 file and copied from there to the final DLL file by the linker,
kono
parents:
diff changeset
1504 where it can be read by the debugger. You must use the
kono
parents:
diff changeset
1505 :switch:`-g` switch if you plan on using the debugger or the symbolic
kono
parents:
diff changeset
1506 stack traceback.
kono
parents:
diff changeset
1507
kono
parents:
diff changeset
1508
kono
parents:
diff changeset
1509 .. index:: -h (gnatdll)
kono
parents:
diff changeset
1510
kono
parents:
diff changeset
1511 :switch:`-h`
kono
parents:
diff changeset
1512 Help mode. Displays ``gnatdll`` switch usage information.
kono
parents:
diff changeset
1513
kono
parents:
diff changeset
1514
kono
parents:
diff changeset
1515 .. index:: -I (gnatdll)
kono
parents:
diff changeset
1516
kono
parents:
diff changeset
1517 :switch:`-I{dir}`
kono
parents:
diff changeset
1518 Direct ``gnatdll`` to search the ``dir`` directory for source and
kono
parents:
diff changeset
1519 object files needed to build the DLL.
kono
parents:
diff changeset
1520 (:ref:`Search_Paths_and_the_Run-Time_Library_RTL`).
kono
parents:
diff changeset
1521
kono
parents:
diff changeset
1522
kono
parents:
diff changeset
1523 .. index:: -k (gnatdll)
kono
parents:
diff changeset
1524
kono
parents:
diff changeset
1525 :switch:`-k`
kono
parents:
diff changeset
1526 Removes the :samp:`@{nn}` suffix from the import library's exported
kono
parents:
diff changeset
1527 names, but keeps them for the link names. You must specify this
kono
parents:
diff changeset
1528 option if you want to use a ``Stdcall`` function in a DLL for which
kono
parents:
diff changeset
1529 the :samp:`@{nn}` suffix has been removed. This is the case for most
kono
parents:
diff changeset
1530 of the Windows NT DLL for example. This option has no effect when
kono
parents:
diff changeset
1531 :switch:`-n` option is specified.
kono
parents:
diff changeset
1532
kono
parents:
diff changeset
1533
kono
parents:
diff changeset
1534 .. index:: -l (gnatdll)
kono
parents:
diff changeset
1535
kono
parents:
diff changeset
1536 :switch:`-l {file}`
kono
parents:
diff changeset
1537 The list of ALI and object files used to build the DLL are listed in
kono
parents:
diff changeset
1538 ``file``, instead of being given in the command line. Each line in
kono
parents:
diff changeset
1539 ``file`` contains the name of an ALI or object file.
kono
parents:
diff changeset
1540
kono
parents:
diff changeset
1541
kono
parents:
diff changeset
1542 .. index:: -n (gnatdll)
kono
parents:
diff changeset
1543
kono
parents:
diff changeset
1544 :switch:`-n`
kono
parents:
diff changeset
1545 No Import. Do not create the import library.
kono
parents:
diff changeset
1546
kono
parents:
diff changeset
1547
kono
parents:
diff changeset
1548 .. index:: -q (gnatdll)
kono
parents:
diff changeset
1549
kono
parents:
diff changeset
1550 :switch:`-q`
kono
parents:
diff changeset
1551 Quiet mode. Do not display unnecessary messages.
kono
parents:
diff changeset
1552
kono
parents:
diff changeset
1553
kono
parents:
diff changeset
1554 .. index:: -v (gnatdll)
kono
parents:
diff changeset
1555
kono
parents:
diff changeset
1556 :switch:`-v`
kono
parents:
diff changeset
1557 Verbose mode. Display extra information.
kono
parents:
diff changeset
1558
kono
parents:
diff changeset
1559
kono
parents:
diff changeset
1560 .. index:: -largs (gnatdll)
kono
parents:
diff changeset
1561
kono
parents:
diff changeset
1562 :switch:`-largs {opts}`
kono
parents:
diff changeset
1563 Linker options. Pass ``opts`` to the linker.
kono
parents:
diff changeset
1564
kono
parents:
diff changeset
1565
kono
parents:
diff changeset
1566 .. rubric:: ``gnatdll`` Example
kono
parents:
diff changeset
1567
kono
parents:
diff changeset
1568 As an example the command to build a relocatable DLL from :file:`api.adb`
kono
parents:
diff changeset
1569 once :file:`api.adb` has been compiled and :file:`api.def` created is
kono
parents:
diff changeset
1570
kono
parents:
diff changeset
1571 ::
kono
parents:
diff changeset
1572
kono
parents:
diff changeset
1573 $ gnatdll -d api.dll api.ali
kono
parents:
diff changeset
1574
kono
parents:
diff changeset
1575 The above command creates two files: :file:`libapi.dll.a` (the import
kono
parents:
diff changeset
1576 library) and :file:`api.dll` (the actual DLL). If you want to create
kono
parents:
diff changeset
1577 only the DLL, just type:
kono
parents:
diff changeset
1578
kono
parents:
diff changeset
1579 ::
kono
parents:
diff changeset
1580
kono
parents:
diff changeset
1581 $ gnatdll -d api.dll -n api.ali
kono
parents:
diff changeset
1582
kono
parents:
diff changeset
1583 Alternatively if you want to create just the import library, type:
kono
parents:
diff changeset
1584
kono
parents:
diff changeset
1585 ::
kono
parents:
diff changeset
1586
kono
parents:
diff changeset
1587 $ gnatdll -d api.dll
kono
parents:
diff changeset
1588
kono
parents:
diff changeset
1589
kono
parents:
diff changeset
1590 .. rubric:: ``gnatdll`` behind the Scenes
kono
parents:
diff changeset
1591
kono
parents:
diff changeset
1592 This section details the steps involved in creating a DLL. ``gnatdll``
kono
parents:
diff changeset
1593 does these steps for you. Unless you are interested in understanding what
kono
parents:
diff changeset
1594 goes on behind the scenes, you should skip this section.
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 We use the previous example of a DLL containing the Ada package ``API``,
kono
parents:
diff changeset
1597 to illustrate the steps necessary to build a DLL. The starting point is a
kono
parents:
diff changeset
1598 set of objects that will make up the DLL and the corresponding ALI
kono
parents:
diff changeset
1599 files. In the case of this example this means that :file:`api.o` and
kono
parents:
diff changeset
1600 :file:`api.ali` are available. To build a relocatable DLL, ``gnatdll`` does
kono
parents:
diff changeset
1601 the following:
kono
parents:
diff changeset
1602
kono
parents:
diff changeset
1603 * ``gnatdll`` builds the base file (:file:`api.base`). A base file gives
kono
parents:
diff changeset
1604 the information necessary to generate relocation information for the
kono
parents:
diff changeset
1605 DLL.
kono
parents:
diff changeset
1606
kono
parents:
diff changeset
1607 ::
kono
parents:
diff changeset
1608
kono
parents:
diff changeset
1609 $ gnatbind -n api
kono
parents:
diff changeset
1610 $ gnatlink api -o api.jnk -mdll -Wl,--base-file,api.base
kono
parents:
diff changeset
1611
kono
parents:
diff changeset
1612 In addition to the base file, the ``gnatlink`` command generates an
kono
parents:
diff changeset
1613 output file :file:`api.jnk` which can be discarded. The :switch:`-mdll` switch
kono
parents:
diff changeset
1614 asks ``gnatlink`` to generate the routines ``DllMain`` and
kono
parents:
diff changeset
1615 ``DllMainCRTStartup`` that are called by the Windows loader when the DLL
kono
parents:
diff changeset
1616 is loaded into memory.
kono
parents:
diff changeset
1617
kono
parents:
diff changeset
1618 * ``gnatdll`` uses ``dlltool`` (see :ref:`Using dlltool <Using_dlltool>`) to build the
kono
parents:
diff changeset
1619 export table (:file:`api.exp`). The export table contains the relocation
kono
parents:
diff changeset
1620 information in a form which can be used during the final link to ensure
kono
parents:
diff changeset
1621 that the Windows loader is able to place the DLL anywhere in memory.
kono
parents:
diff changeset
1622
kono
parents:
diff changeset
1623 ::
kono
parents:
diff changeset
1624
kono
parents:
diff changeset
1625 $ dlltool --dllname api.dll --def api.def --base-file api.base \\
kono
parents:
diff changeset
1626 --output-exp api.exp
kono
parents:
diff changeset
1627
kono
parents:
diff changeset
1628 * ``gnatdll`` builds the base file using the new export table. Note that
kono
parents:
diff changeset
1629 ``gnatbind`` must be called once again since the binder generated file
kono
parents:
diff changeset
1630 has been deleted during the previous call to ``gnatlink``.
kono
parents:
diff changeset
1631
kono
parents:
diff changeset
1632 ::
kono
parents:
diff changeset
1633
kono
parents:
diff changeset
1634 $ gnatbind -n api
kono
parents:
diff changeset
1635 $ gnatlink api -o api.jnk api.exp -mdll
kono
parents:
diff changeset
1636 -Wl,--base-file,api.base
kono
parents:
diff changeset
1637
kono
parents:
diff changeset
1638
kono
parents:
diff changeset
1639 * ``gnatdll`` builds the new export table using the new base file and
kono
parents:
diff changeset
1640 generates the DLL import library :file:`libAPI.dll.a`.
kono
parents:
diff changeset
1641
kono
parents:
diff changeset
1642
kono
parents:
diff changeset
1643 ::
kono
parents:
diff changeset
1644
kono
parents:
diff changeset
1645 $ dlltool --dllname api.dll --def api.def --base-file api.base \\
kono
parents:
diff changeset
1646 --output-exp api.exp --output-lib libAPI.a
kono
parents:
diff changeset
1647
kono
parents:
diff changeset
1648 * Finally ``gnatdll`` builds the relocatable DLL using the final export
kono
parents:
diff changeset
1649 table.
kono
parents:
diff changeset
1650
kono
parents:
diff changeset
1651 ::
kono
parents:
diff changeset
1652
kono
parents:
diff changeset
1653 $ gnatbind -n api
kono
parents:
diff changeset
1654 $ gnatlink api api.exp -o api.dll -mdll
kono
parents:
diff changeset
1655
kono
parents:
diff changeset
1656
kono
parents:
diff changeset
1657 .. _Using_dlltool:
kono
parents:
diff changeset
1658
kono
parents:
diff changeset
1659 .. rubric:: Using ``dlltool``
kono
parents:
diff changeset
1660
kono
parents:
diff changeset
1661 ``dlltool`` is the low-level tool used by ``gnatdll`` to build
kono
parents:
diff changeset
1662 DLLs and static import libraries. This section summarizes the most
kono
parents:
diff changeset
1663 common ``dlltool`` switches. The form of the ``dlltool`` command
kono
parents:
diff changeset
1664 is
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 ::
kono
parents:
diff changeset
1667
kono
parents:
diff changeset
1668 $ dlltool [`switches`]
kono
parents:
diff changeset
1669
kono
parents:
diff changeset
1670 ``dlltool`` switches include:
kono
parents:
diff changeset
1671
kono
parents:
diff changeset
1672
kono
parents:
diff changeset
1673 .. index:: --base-file (dlltool)
kono
parents:
diff changeset
1674
kono
parents:
diff changeset
1675 :switch:`--base-file {basefile}`
kono
parents:
diff changeset
1676 Read the base file ``basefile`` generated by the linker. This switch
kono
parents:
diff changeset
1677 is used to create a relocatable DLL.
kono
parents:
diff changeset
1678
kono
parents:
diff changeset
1679
kono
parents:
diff changeset
1680 .. index:: --def (dlltool)
kono
parents:
diff changeset
1681
kono
parents:
diff changeset
1682 :switch:`--def {deffile}`
kono
parents:
diff changeset
1683 Read the definition file.
kono
parents:
diff changeset
1684
kono
parents:
diff changeset
1685
kono
parents:
diff changeset
1686 .. index:: --dllname (dlltool)
kono
parents:
diff changeset
1687
kono
parents:
diff changeset
1688 :switch:`--dllname {name}`
kono
parents:
diff changeset
1689 Gives the name of the DLL. This switch is used to embed the name of the
kono
parents:
diff changeset
1690 DLL in the static import library generated by ``dlltool`` with switch
kono
parents:
diff changeset
1691 :switch:`--output-lib`.
kono
parents:
diff changeset
1692
kono
parents:
diff changeset
1693
kono
parents:
diff changeset
1694 .. index:: -k (dlltool)
kono
parents:
diff changeset
1695
kono
parents:
diff changeset
1696 :switch:`-k`
kono
parents:
diff changeset
1697 Kill :samp:`@{nn}` from exported names
kono
parents:
diff changeset
1698 (:ref:`Windows_Calling_Conventions`
kono
parents:
diff changeset
1699 for a discussion about ``Stdcall``-style symbols.
kono
parents:
diff changeset
1700
kono
parents:
diff changeset
1701
kono
parents:
diff changeset
1702 .. index:: --help (dlltool)
kono
parents:
diff changeset
1703
kono
parents:
diff changeset
1704 :switch:`--help`
kono
parents:
diff changeset
1705 Prints the ``dlltool`` switches with a concise description.
kono
parents:
diff changeset
1706
kono
parents:
diff changeset
1707
kono
parents:
diff changeset
1708 .. index:: --output-exp (dlltool)
kono
parents:
diff changeset
1709
kono
parents:
diff changeset
1710 :switch:`--output-exp {exportfile}`
kono
parents:
diff changeset
1711 Generate an export file ``exportfile``. The export file contains the
kono
parents:
diff changeset
1712 export table (list of symbols in the DLL) and is used to create the DLL.
kono
parents:
diff changeset
1713
kono
parents:
diff changeset
1714
kono
parents:
diff changeset
1715 .. index:: --output-lib (dlltool)
kono
parents:
diff changeset
1716
kono
parents:
diff changeset
1717 :switch:`--output-lib {libfile}`
kono
parents:
diff changeset
1718 Generate a static import library ``libfile``.
kono
parents:
diff changeset
1719
kono
parents:
diff changeset
1720
kono
parents:
diff changeset
1721 .. index:: -v (dlltool)
kono
parents:
diff changeset
1722
kono
parents:
diff changeset
1723 :switch:`-v`
kono
parents:
diff changeset
1724 Verbose mode.
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726
kono
parents:
diff changeset
1727 .. index:: --as (dlltool)
kono
parents:
diff changeset
1728
kono
parents:
diff changeset
1729 :switch:`--as {assembler-name}`
kono
parents:
diff changeset
1730 Use ``assembler-name`` as the assembler. The default is ``as``.
kono
parents:
diff changeset
1731
kono
parents:
diff changeset
1732
kono
parents:
diff changeset
1733 .. _GNAT_and_Windows_Resources:
kono
parents:
diff changeset
1734
kono
parents:
diff changeset
1735 GNAT and Windows Resources
kono
parents:
diff changeset
1736 ^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1737
kono
parents:
diff changeset
1738 .. index:: Resources, windows
kono
parents:
diff changeset
1739
kono
parents:
diff changeset
1740 Resources are an easy way to add Windows specific objects to your
kono
parents:
diff changeset
1741 application. The objects that can be added as resources include:
kono
parents:
diff changeset
1742
kono
parents:
diff changeset
1743 * menus
kono
parents:
diff changeset
1744
kono
parents:
diff changeset
1745 * accelerators
kono
parents:
diff changeset
1746
kono
parents:
diff changeset
1747 * dialog boxes
kono
parents:
diff changeset
1748
kono
parents:
diff changeset
1749 * string tables
kono
parents:
diff changeset
1750
kono
parents:
diff changeset
1751 * bitmaps
kono
parents:
diff changeset
1752
kono
parents:
diff changeset
1753 * cursors
kono
parents:
diff changeset
1754
kono
parents:
diff changeset
1755 * icons
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 * fonts
kono
parents:
diff changeset
1758
kono
parents:
diff changeset
1759 * version information
kono
parents:
diff changeset
1760
kono
parents:
diff changeset
1761 For example, a version information resource can be defined as follow and
kono
parents:
diff changeset
1762 embedded into an executable or DLL:
kono
parents:
diff changeset
1763
kono
parents:
diff changeset
1764 A version information resource can be used to embed information into an
kono
parents:
diff changeset
1765 executable or a DLL. These information can be viewed using the file properties
kono
parents:
diff changeset
1766 from the Windows Explorer. Here is an example of a version information
kono
parents:
diff changeset
1767 resource:
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 ::
kono
parents:
diff changeset
1770
kono
parents:
diff changeset
1771 1 VERSIONINFO
kono
parents:
diff changeset
1772 FILEVERSION 1,0,0,0
kono
parents:
diff changeset
1773 PRODUCTVERSION 1,0,0,0
kono
parents:
diff changeset
1774 BEGIN
kono
parents:
diff changeset
1775 BLOCK "StringFileInfo"
kono
parents:
diff changeset
1776 BEGIN
kono
parents:
diff changeset
1777 BLOCK "080904E4"
kono
parents:
diff changeset
1778 BEGIN
kono
parents:
diff changeset
1779 VALUE "CompanyName", "My Company Name"
kono
parents:
diff changeset
1780 VALUE "FileDescription", "My application"
kono
parents:
diff changeset
1781 VALUE "FileVersion", "1.0"
kono
parents:
diff changeset
1782 VALUE "InternalName", "my_app"
kono
parents:
diff changeset
1783 VALUE "LegalCopyright", "My Name"
kono
parents:
diff changeset
1784 VALUE "OriginalFilename", "my_app.exe"
kono
parents:
diff changeset
1785 VALUE "ProductName", "My App"
kono
parents:
diff changeset
1786 VALUE "ProductVersion", "1.0"
kono
parents:
diff changeset
1787 END
kono
parents:
diff changeset
1788 END
kono
parents:
diff changeset
1789
kono
parents:
diff changeset
1790 BLOCK "VarFileInfo"
kono
parents:
diff changeset
1791 BEGIN
kono
parents:
diff changeset
1792 VALUE "Translation", 0x809, 1252
kono
parents:
diff changeset
1793 END
kono
parents:
diff changeset
1794 END
kono
parents:
diff changeset
1795
kono
parents:
diff changeset
1796 The value ``0809`` (langID) is for the U.K English language and
kono
parents:
diff changeset
1797 ``04E4`` (charsetID), which is equal to ``1252`` decimal, for
kono
parents:
diff changeset
1798 multilingual.
kono
parents:
diff changeset
1799
kono
parents:
diff changeset
1800 This section explains how to build, compile and use resources. Note that this
kono
parents:
diff changeset
1801 section does not cover all resource objects, for a complete description see
kono
parents:
diff changeset
1802 the corresponding Microsoft documentation.
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804
kono
parents:
diff changeset
1805 .. _Building_Resources:
kono
parents:
diff changeset
1806
kono
parents:
diff changeset
1807 Building Resources
kono
parents:
diff changeset
1808 """"""""""""""""""
kono
parents:
diff changeset
1809
kono
parents:
diff changeset
1810 .. index:: Resources, building
kono
parents:
diff changeset
1811
kono
parents:
diff changeset
1812 A resource file is an ASCII file. By convention resource files have an
kono
parents:
diff changeset
1813 :file:`.rc` extension.
kono
parents:
diff changeset
1814 The easiest way to build a resource file is to use Microsoft tools
kono
parents:
diff changeset
1815 such as ``imagedit.exe`` to build bitmaps, icons and cursors and
kono
parents:
diff changeset
1816 ``dlgedit.exe`` to build dialogs.
kono
parents:
diff changeset
1817 It is always possible to build an :file:`.rc` file yourself by writing a
kono
parents:
diff changeset
1818 resource script.
kono
parents:
diff changeset
1819
kono
parents:
diff changeset
1820 It is not our objective to explain how to write a resource file. A
kono
parents:
diff changeset
1821 complete description of the resource script language can be found in the
kono
parents:
diff changeset
1822 Microsoft documentation.
kono
parents:
diff changeset
1823
kono
parents:
diff changeset
1824
kono
parents:
diff changeset
1825 .. _Compiling_Resources:
kono
parents:
diff changeset
1826
kono
parents:
diff changeset
1827 Compiling Resources
kono
parents:
diff changeset
1828 """""""""""""""""""
kono
parents:
diff changeset
1829
kono
parents:
diff changeset
1830 .. index:: rc
kono
parents:
diff changeset
1831 .. index:: windres
kono
parents:
diff changeset
1832 .. index:: Resources, compiling
kono
parents:
diff changeset
1833
kono
parents:
diff changeset
1834 This section describes how to build a GNAT-compatible (COFF) object file
kono
parents:
diff changeset
1835 containing the resources. This is done using the Resource Compiler
kono
parents:
diff changeset
1836 ``windres`` as follows:
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 ::
kono
parents:
diff changeset
1839
kono
parents:
diff changeset
1840 $ windres -i myres.rc -o myres.o
kono
parents:
diff changeset
1841
kono
parents:
diff changeset
1842 By default ``windres`` will run ``gcc`` to preprocess the :file:`.rc`
kono
parents:
diff changeset
1843 file. You can specify an alternate preprocessor (usually named
kono
parents:
diff changeset
1844 :file:`cpp.exe`) using the ``windres`` :switch:`--preprocessor`
kono
parents:
diff changeset
1845 parameter. A list of all possible options may be obtained by entering
kono
parents:
diff changeset
1846 the command ``windres`` :switch:`--help`.
kono
parents:
diff changeset
1847
kono
parents:
diff changeset
1848 It is also possible to use the Microsoft resource compiler ``rc.exe``
kono
parents:
diff changeset
1849 to produce a :file:`.res` file (binary resource file). See the
kono
parents:
diff changeset
1850 corresponding Microsoft documentation for further details. In this case
kono
parents:
diff changeset
1851 you need to use ``windres`` to translate the :file:`.res` file to a
kono
parents:
diff changeset
1852 GNAT-compatible object file as follows:
kono
parents:
diff changeset
1853
kono
parents:
diff changeset
1854 ::
kono
parents:
diff changeset
1855
kono
parents:
diff changeset
1856 $ windres -i myres.res -o myres.o
kono
parents:
diff changeset
1857
kono
parents:
diff changeset
1858
kono
parents:
diff changeset
1859 .. _Using_Resources:
kono
parents:
diff changeset
1860
kono
parents:
diff changeset
1861 Using Resources
kono
parents:
diff changeset
1862 """""""""""""""
kono
parents:
diff changeset
1863
kono
parents:
diff changeset
1864 .. index:: Resources, using
kono
parents:
diff changeset
1865
kono
parents:
diff changeset
1866 To include the resource file in your program just add the
kono
parents:
diff changeset
1867 GNAT-compatible object file for the resource(s) to the linker
kono
parents:
diff changeset
1868 arguments. With ``gnatmake`` this is done by using the :switch:`-largs`
kono
parents:
diff changeset
1869 option:
kono
parents:
diff changeset
1870
kono
parents:
diff changeset
1871 ::
kono
parents:
diff changeset
1872
kono
parents:
diff changeset
1873 $ gnatmake myprog -largs myres.o
kono
parents:
diff changeset
1874
kono
parents:
diff changeset
1875
kono
parents:
diff changeset
1876 .. _Using_GNAT_DLL_from_MSVS:
kono
parents:
diff changeset
1877
kono
parents:
diff changeset
1878 Using GNAT DLLs from Microsoft Visual Studio Applications
kono
parents:
diff changeset
1879 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1880
kono
parents:
diff changeset
1881 .. index:: Microsoft Visual Studio, use with GNAT DLLs
kono
parents:
diff changeset
1882
kono
parents:
diff changeset
1883 This section describes a common case of mixed GNAT/Microsoft Visual Studio
kono
parents:
diff changeset
1884 application development, where the main program is developed using MSVS, and
kono
parents:
diff changeset
1885 is linked with a DLL developed using GNAT. Such a mixed application should
kono
parents:
diff changeset
1886 be developed following the general guidelines outlined above; below is the
kono
parents:
diff changeset
1887 cookbook-style sequence of steps to follow:
kono
parents:
diff changeset
1888
kono
parents:
diff changeset
1889 1. First develop and build the GNAT shared library using a library project
kono
parents:
diff changeset
1890 (let's assume the project is :file:`mylib.gpr`, producing the library :file:`libmylib.dll`):
kono
parents:
diff changeset
1891
kono
parents:
diff changeset
1892 ::
kono
parents:
diff changeset
1893
kono
parents:
diff changeset
1894 $ gprbuild -p mylib.gpr
kono
parents:
diff changeset
1895
kono
parents:
diff changeset
1896 2. Produce a .def file for the symbols you need to interface with, either by
kono
parents:
diff changeset
1897 hand or automatically with possibly some manual adjustments
kono
parents:
diff changeset
1898 (see :ref:`Creating Definition File Automatically <Create_Def_File_Automatically>`):
kono
parents:
diff changeset
1899
kono
parents:
diff changeset
1900 ::
kono
parents:
diff changeset
1901
kono
parents:
diff changeset
1902 $ dlltool libmylib.dll -z libmylib.def --export-all-symbols
kono
parents:
diff changeset
1903
kono
parents:
diff changeset
1904 3. Make sure that MSVS command-line tools are accessible on the path.
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 4. Create the Microsoft-style import library (see :ref:`MSVS-Style Import Library <MSVS-Style_Import_Library>`):
kono
parents:
diff changeset
1907
kono
parents:
diff changeset
1908 ::
kono
parents:
diff changeset
1909
kono
parents:
diff changeset
1910 $ lib -machine:IX86 -def:libmylib.def -out:libmylib.lib
kono
parents:
diff changeset
1911
kono
parents:
diff changeset
1912 If you are using a 64-bit toolchain, the above becomes...
kono
parents:
diff changeset
1913
kono
parents:
diff changeset
1914 ::
kono
parents:
diff changeset
1915
kono
parents:
diff changeset
1916 $ lib -machine:X64 -def:libmylib.def -out:libmylib.lib
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 5. Build the C main
kono
parents:
diff changeset
1919
kono
parents:
diff changeset
1920 ::
kono
parents:
diff changeset
1921
kono
parents:
diff changeset
1922 $ cl /O2 /MD main.c libmylib.lib
kono
parents:
diff changeset
1923
kono
parents:
diff changeset
1924 6. Before running the executable, make sure you have set the PATH to the DLL,
kono
parents:
diff changeset
1925 or copy the DLL into into the directory containing the .exe.
kono
parents:
diff changeset
1926
kono
parents:
diff changeset
1927
kono
parents:
diff changeset
1928 .. _Debugging_a_DLL:
kono
parents:
diff changeset
1929
kono
parents:
diff changeset
1930 Debugging a DLL
kono
parents:
diff changeset
1931 ^^^^^^^^^^^^^^^
kono
parents:
diff changeset
1932
kono
parents:
diff changeset
1933 .. index:: DLL debugging
kono
parents:
diff changeset
1934
kono
parents:
diff changeset
1935 Debugging a DLL is similar to debugging a standard program. But
kono
parents:
diff changeset
1936 we have to deal with two different executable parts: the DLL and the
kono
parents:
diff changeset
1937 program that uses it. We have the following four possibilities:
kono
parents:
diff changeset
1938
kono
parents:
diff changeset
1939 * The program and the DLL are built with GCC/GNAT.
kono
parents:
diff changeset
1940 * The program is built with foreign tools and the DLL is built with
kono
parents:
diff changeset
1941 GCC/GNAT.
kono
parents:
diff changeset
1942 * The program is built with GCC/GNAT and the DLL is built with
kono
parents:
diff changeset
1943 foreign tools.
kono
parents:
diff changeset
1944
kono
parents:
diff changeset
1945 In this section we address only cases one and two above.
kono
parents:
diff changeset
1946 There is no point in trying to debug
kono
parents:
diff changeset
1947 a DLL with GNU/GDB, if there is no GDB-compatible debugging
kono
parents:
diff changeset
1948 information in it. To do so you must use a debugger compatible with the
kono
parents:
diff changeset
1949 tools suite used to build the DLL.
kono
parents:
diff changeset
1950
kono
parents:
diff changeset
1951 .. _Program_and_DLL_Both_Built_with_GCC/GNAT:
kono
parents:
diff changeset
1952
kono
parents:
diff changeset
1953 Program and DLL Both Built with GCC/GNAT
kono
parents:
diff changeset
1954 """"""""""""""""""""""""""""""""""""""""
kono
parents:
diff changeset
1955
kono
parents:
diff changeset
1956 This is the simplest case. Both the DLL and the program have ``GDB``
kono
parents:
diff changeset
1957 compatible debugging information. It is then possible to break anywhere in
kono
parents:
diff changeset
1958 the process. Let's suppose here that the main procedure is named
kono
parents:
diff changeset
1959 ``ada_main`` and that in the DLL there is an entry point named
kono
parents:
diff changeset
1960 ``ada_dll``.
kono
parents:
diff changeset
1961
kono
parents:
diff changeset
1962 The DLL (:ref:`Introduction_to_Dynamic_Link_Libraries_DLLs`) and
kono
parents:
diff changeset
1963 program must have been built with the debugging information (see GNAT -g
kono
parents:
diff changeset
1964 switch). Here are the step-by-step instructions for debugging it:
kono
parents:
diff changeset
1965
kono
parents:
diff changeset
1966 * Launch ``GDB`` on the main program.
kono
parents:
diff changeset
1967
kono
parents:
diff changeset
1968 ::
kono
parents:
diff changeset
1969
kono
parents:
diff changeset
1970 $ gdb -nw ada_main
kono
parents:
diff changeset
1971
kono
parents:
diff changeset
1972 * Start the program and stop at the beginning of the main procedure
kono
parents:
diff changeset
1973
kono
parents:
diff changeset
1974 ::
kono
parents:
diff changeset
1975
kono
parents:
diff changeset
1976 (gdb) start
kono
parents:
diff changeset
1977
kono
parents:
diff changeset
1978 This step is required to be able to set a breakpoint inside the DLL. As long
kono
parents:
diff changeset
1979 as the program is not run, the DLL is not loaded. This has the
kono
parents:
diff changeset
1980 consequence that the DLL debugging information is also not loaded, so it is not
kono
parents:
diff changeset
1981 possible to set a breakpoint in the DLL.
kono
parents:
diff changeset
1982
kono
parents:
diff changeset
1983 * Set a breakpoint inside the DLL
kono
parents:
diff changeset
1984
kono
parents:
diff changeset
1985 ::
kono
parents:
diff changeset
1986
kono
parents:
diff changeset
1987 (gdb) break ada_dll
kono
parents:
diff changeset
1988 (gdb) cont
kono
parents:
diff changeset
1989
kono
parents:
diff changeset
1990 At this stage a breakpoint is set inside the DLL. From there on
kono
parents:
diff changeset
1991 you can use the standard approach to debug the whole program
kono
parents:
diff changeset
1992 (:ref:`Running_and_Debugging_Ada_Programs`).
kono
parents:
diff changeset
1993
kono
parents:
diff changeset
1994
kono
parents:
diff changeset
1995 .. _Program_Built_with_Foreign_Tools_and_DLL_Built_with_GCC/GNAT:
kono
parents:
diff changeset
1996
kono
parents:
diff changeset
1997 Program Built with Foreign Tools and DLL Built with GCC/GNAT
kono
parents:
diff changeset
1998 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""
kono
parents:
diff changeset
1999
kono
parents:
diff changeset
2000 In this case things are slightly more complex because it is not possible to
kono
parents:
diff changeset
2001 start the main program and then break at the beginning to load the DLL and the
kono
parents:
diff changeset
2002 associated DLL debugging information. It is not possible to break at the
kono
parents:
diff changeset
2003 beginning of the program because there is no ``GDB`` debugging information,
kono
parents:
diff changeset
2004 and therefore there is no direct way of getting initial control. This
kono
parents:
diff changeset
2005 section addresses this issue by describing some methods that can be used
kono
parents:
diff changeset
2006 to break somewhere in the DLL to debug it.
kono
parents:
diff changeset
2007
kono
parents:
diff changeset
2008 First suppose that the main procedure is named ``main`` (this is for
kono
parents:
diff changeset
2009 example some C code built with Microsoft Visual C) and that there is a
kono
parents:
diff changeset
2010 DLL named ``test.dll`` containing an Ada entry point named
kono
parents:
diff changeset
2011 ``ada_dll``.
kono
parents:
diff changeset
2012
kono
parents:
diff changeset
2013 The DLL (see :ref:`Introduction_to_Dynamic_Link_Libraries_DLLs`) must have
kono
parents:
diff changeset
2014 been built with debugging information (see the GNAT :switch:`-g` option).
kono
parents:
diff changeset
2015
kono
parents:
diff changeset
2016
kono
parents:
diff changeset
2017 .. rubric:: Debugging the DLL Directly
kono
parents:
diff changeset
2018
kono
parents:
diff changeset
2019 * Find out the executable starting address
kono
parents:
diff changeset
2020
kono
parents:
diff changeset
2021 ::
kono
parents:
diff changeset
2022
kono
parents:
diff changeset
2023 $ objdump --file-header main.exe
kono
parents:
diff changeset
2024
kono
parents:
diff changeset
2025 The starting address is reported on the last line. For example:
kono
parents:
diff changeset
2026
kono
parents:
diff changeset
2027 ::
kono
parents:
diff changeset
2028
kono
parents:
diff changeset
2029 main.exe: file format pei-i386
kono
parents:
diff changeset
2030 architecture: i386, flags 0x0000010a:
kono
parents:
diff changeset
2031 EXEC_P, HAS_DEBUG, D_PAGED
kono
parents:
diff changeset
2032 start address 0x00401010
kono
parents:
diff changeset
2033
kono
parents:
diff changeset
2034 * Launch the debugger on the executable.
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 ::
kono
parents:
diff changeset
2037
kono
parents:
diff changeset
2038 $ gdb main.exe
kono
parents:
diff changeset
2039
kono
parents:
diff changeset
2040 * Set a breakpoint at the starting address, and launch the program.
kono
parents:
diff changeset
2041
kono
parents:
diff changeset
2042 ::
kono
parents:
diff changeset
2043
kono
parents:
diff changeset
2044 $ (gdb) break *0x00401010
kono
parents:
diff changeset
2045 $ (gdb) run
kono
parents:
diff changeset
2046
kono
parents:
diff changeset
2047 The program will stop at the given address.
kono
parents:
diff changeset
2048
kono
parents:
diff changeset
2049 * Set a breakpoint on a DLL subroutine.
kono
parents:
diff changeset
2050
kono
parents:
diff changeset
2051 ::
kono
parents:
diff changeset
2052
kono
parents:
diff changeset
2053 (gdb) break ada_dll.adb:45
kono
parents:
diff changeset
2054
kono
parents:
diff changeset
2055 Or if you want to break using a symbol on the DLL, you need first to
kono
parents:
diff changeset
2056 select the Ada language (language used by the DLL).
kono
parents:
diff changeset
2057
kono
parents:
diff changeset
2058 ::
kono
parents:
diff changeset
2059
kono
parents:
diff changeset
2060 (gdb) set language ada
kono
parents:
diff changeset
2061 (gdb) break ada_dll
kono
parents:
diff changeset
2062
kono
parents:
diff changeset
2063 * Continue the program.
kono
parents:
diff changeset
2064
kono
parents:
diff changeset
2065 ::
kono
parents:
diff changeset
2066
kono
parents:
diff changeset
2067 (gdb) cont
kono
parents:
diff changeset
2068
kono
parents:
diff changeset
2069 This will run the program until it reaches the breakpoint that has been
kono
parents:
diff changeset
2070 set. From that point you can use the standard way to debug a program
kono
parents:
diff changeset
2071 as described in (:ref:`Running_and_Debugging_Ada_Programs`).
kono
parents:
diff changeset
2072
kono
parents:
diff changeset
2073 It is also possible to debug the DLL by attaching to a running process.
kono
parents:
diff changeset
2074
kono
parents:
diff changeset
2075
kono
parents:
diff changeset
2076 .. rubric:: Attaching to a Running Process
kono
parents:
diff changeset
2077
kono
parents:
diff changeset
2078 .. index:: DLL debugging, attach to process
kono
parents:
diff changeset
2079
kono
parents:
diff changeset
2080 With ``GDB`` it is always possible to debug a running process by
kono
parents:
diff changeset
2081 attaching to it. It is possible to debug a DLL this way. The limitation
kono
parents:
diff changeset
2082 of this approach is that the DLL must run long enough to perform the
kono
parents:
diff changeset
2083 attach operation. It may be useful for instance to insert a time wasting
kono
parents:
diff changeset
2084 loop in the code of the DLL to meet this criterion.
kono
parents:
diff changeset
2085
kono
parents:
diff changeset
2086 * Launch the main program :file:`main.exe`.
kono
parents:
diff changeset
2087
kono
parents:
diff changeset
2088 ::
kono
parents:
diff changeset
2089
kono
parents:
diff changeset
2090 $ main
kono
parents:
diff changeset
2091
kono
parents:
diff changeset
2092 * Use the Windows *Task Manager* to find the process ID. Let's say
kono
parents:
diff changeset
2093 that the process PID for :file:`main.exe` is 208.
kono
parents:
diff changeset
2094
kono
parents:
diff changeset
2095 * Launch gdb.
kono
parents:
diff changeset
2096
kono
parents:
diff changeset
2097 ::
kono
parents:
diff changeset
2098
kono
parents:
diff changeset
2099 $ gdb
kono
parents:
diff changeset
2100
kono
parents:
diff changeset
2101 * Attach to the running process to be debugged.
kono
parents:
diff changeset
2102
kono
parents:
diff changeset
2103 ::
kono
parents:
diff changeset
2104
kono
parents:
diff changeset
2105 (gdb) attach 208
kono
parents:
diff changeset
2106
kono
parents:
diff changeset
2107 * Load the process debugging information.
kono
parents:
diff changeset
2108
kono
parents:
diff changeset
2109 ::
kono
parents:
diff changeset
2110
kono
parents:
diff changeset
2111 (gdb) symbol-file main.exe
kono
parents:
diff changeset
2112
kono
parents:
diff changeset
2113 * Break somewhere in the DLL.
kono
parents:
diff changeset
2114
kono
parents:
diff changeset
2115 ::
kono
parents:
diff changeset
2116
kono
parents:
diff changeset
2117 (gdb) break ada_dll
kono
parents:
diff changeset
2118
kono
parents:
diff changeset
2119 * Continue process execution.
kono
parents:
diff changeset
2120
kono
parents:
diff changeset
2121 ::
kono
parents:
diff changeset
2122
kono
parents:
diff changeset
2123 (gdb) cont
kono
parents:
diff changeset
2124
kono
parents:
diff changeset
2125 This last step will resume the process execution, and stop at
kono
parents:
diff changeset
2126 the breakpoint we have set. From there you can use the standard
kono
parents:
diff changeset
2127 approach to debug a program as described in
kono
parents:
diff changeset
2128 :ref:`Running_and_Debugging_Ada_Programs`.
kono
parents:
diff changeset
2129
kono
parents:
diff changeset
2130
kono
parents:
diff changeset
2131 .. _Setting_Stack_Size_from_gnatlink:
kono
parents:
diff changeset
2132
kono
parents:
diff changeset
2133 Setting Stack Size from ``gnatlink``
kono
parents:
diff changeset
2134 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
2135
kono
parents:
diff changeset
2136 It is possible to specify the program stack size at link time. On modern
kono
parents:
diff changeset
2137 versions of Windows, starting with XP, this is mostly useful to set the size of
kono
parents:
diff changeset
2138 the main stack (environment task). The other task stacks are set with pragma
kono
parents:
diff changeset
2139 Storage_Size or with the *gnatbind -d* command.
kono
parents:
diff changeset
2140
kono
parents:
diff changeset
2141 Since older versions of Windows (2000, NT4, etc.) do not allow setting the
kono
parents:
diff changeset
2142 reserve size of individual tasks, the link-time stack size applies to all
kono
parents:
diff changeset
2143 tasks, and pragma Storage_Size has no effect.
kono
parents:
diff changeset
2144 In particular, Stack Overflow checks are made against this
kono
parents:
diff changeset
2145 link-time specified size.
kono
parents:
diff changeset
2146
kono
parents:
diff changeset
2147 This setting can be done with ``gnatlink`` using either of the following:
kono
parents:
diff changeset
2148
kono
parents:
diff changeset
2149
kono
parents:
diff changeset
2150 * :switch:`-Xlinker` linker option
kono
parents:
diff changeset
2151
kono
parents:
diff changeset
2152 ::
kono
parents:
diff changeset
2153
kono
parents:
diff changeset
2154 $ gnatlink hello -Xlinker --stack=0x10000,0x1000
kono
parents:
diff changeset
2155
kono
parents:
diff changeset
2156
kono
parents:
diff changeset
2157 This sets the stack reserve size to 0x10000 bytes and the stack commit
kono
parents:
diff changeset
2158 size to 0x1000 bytes.
kono
parents:
diff changeset
2159
kono
parents:
diff changeset
2160 * :switch:`-Wl` linker option
kono
parents:
diff changeset
2161
kono
parents:
diff changeset
2162 ::
kono
parents:
diff changeset
2163
kono
parents:
diff changeset
2164 $ gnatlink hello -Wl,--stack=0x1000000
kono
parents:
diff changeset
2165
kono
parents:
diff changeset
2166 This sets the stack reserve size to 0x1000000 bytes. Note that with
kono
parents:
diff changeset
2167 :switch:`-Wl` option it is not possible to set the stack commit size
kono
parents:
diff changeset
2168 because the comma is a separator for this option.
kono
parents:
diff changeset
2169
kono
parents:
diff changeset
2170
kono
parents:
diff changeset
2171 .. _Setting_Heap_Size_from_gnatlink:
kono
parents:
diff changeset
2172
kono
parents:
diff changeset
2173 Setting Heap Size from ``gnatlink``
kono
parents:
diff changeset
2174 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
kono
parents:
diff changeset
2175
kono
parents:
diff changeset
2176 Under Windows systems, it is possible to specify the program heap size from
kono
parents:
diff changeset
2177 ``gnatlink`` using either of the following:
kono
parents:
diff changeset
2178
kono
parents:
diff changeset
2179 * :switch:`-Xlinker` linker option
kono
parents:
diff changeset
2180
kono
parents:
diff changeset
2181 ::
kono
parents:
diff changeset
2182
kono
parents:
diff changeset
2183 $ gnatlink hello -Xlinker --heap=0x10000,0x1000
kono
parents:
diff changeset
2184
kono
parents:
diff changeset
2185 This sets the heap reserve size to 0x10000 bytes and the heap commit
kono
parents:
diff changeset
2186 size to 0x1000 bytes.
kono
parents:
diff changeset
2187
kono
parents:
diff changeset
2188 * :switch:`-Wl` linker option
kono
parents:
diff changeset
2189
kono
parents:
diff changeset
2190 ::
kono
parents:
diff changeset
2191
kono
parents:
diff changeset
2192 $ gnatlink hello -Wl,--heap=0x1000000
kono
parents:
diff changeset
2193
kono
parents:
diff changeset
2194
kono
parents:
diff changeset
2195 This sets the heap reserve size to 0x1000000 bytes. Note that with
kono
parents:
diff changeset
2196 :switch:`-Wl` option it is not possible to set the heap commit size
kono
parents:
diff changeset
2197 because the comma is a separator for this option.
kono
parents:
diff changeset
2198
kono
parents:
diff changeset
2199
kono
parents:
diff changeset
2200 .. _Win32_Specific_Addons:
kono
parents:
diff changeset
2201
kono
parents:
diff changeset
2202 Windows Specific Add-Ons
kono
parents:
diff changeset
2203 -------------------------
kono
parents:
diff changeset
2204
kono
parents:
diff changeset
2205 This section describes the Windows specific add-ons.
kono
parents:
diff changeset
2206
kono
parents:
diff changeset
2207 .. _Win32Ada:
kono
parents:
diff changeset
2208
kono
parents:
diff changeset
2209 Win32Ada
kono
parents:
diff changeset
2210 ^^^^^^^^
kono
parents:
diff changeset
2211
kono
parents:
diff changeset
2212 Win32Ada is a binding for the Microsoft Win32 API. This binding can be
kono
parents:
diff changeset
2213 easily installed from the provided installer. To use the Win32Ada
kono
parents:
diff changeset
2214 binding you need to use a project file, and adding a single with_clause
kono
parents:
diff changeset
2215 will give you full access to the Win32Ada binding sources and ensure
kono
parents:
diff changeset
2216 that the proper libraries are passed to the linker.
kono
parents:
diff changeset
2217
kono
parents:
diff changeset
2218 .. code-block:: gpr
kono
parents:
diff changeset
2219
kono
parents:
diff changeset
2220 with "win32ada";
kono
parents:
diff changeset
2221 project P is
kono
parents:
diff changeset
2222 for Sources use ...;
kono
parents:
diff changeset
2223 end P;
kono
parents:
diff changeset
2224
kono
parents:
diff changeset
2225 To build the application you just need to call gprbuild for the
kono
parents:
diff changeset
2226 application's project, here p.gpr:
kono
parents:
diff changeset
2227
kono
parents:
diff changeset
2228 .. code-block:: sh
kono
parents:
diff changeset
2229
kono
parents:
diff changeset
2230 gprbuild p.gpr
kono
parents:
diff changeset
2231
kono
parents:
diff changeset
2232 .. _wPOSIX:
kono
parents:
diff changeset
2233
kono
parents:
diff changeset
2234 wPOSIX
kono
parents:
diff changeset
2235 ^^^^^^
kono
parents:
diff changeset
2236
kono
parents:
diff changeset
2237 wPOSIX is a minimal POSIX binding whose goal is to help with building
kono
parents:
diff changeset
2238 cross-platforms applications. This binding is not complete though, as
kono
parents:
diff changeset
2239 the Win32 API does not provide the necessary support for all POSIX APIs.
kono
parents:
diff changeset
2240
kono
parents:
diff changeset
2241 To use the wPOSIX binding you need to use a project file, and adding
kono
parents:
diff changeset
2242 a single with_clause will give you full access to the wPOSIX binding
kono
parents:
diff changeset
2243 sources and ensure that the proper libraries are passed to the linker.
kono
parents:
diff changeset
2244
kono
parents:
diff changeset
2245 .. code-block:: gpr
kono
parents:
diff changeset
2246
kono
parents:
diff changeset
2247 with "wposix";
kono
parents:
diff changeset
2248 project P is
kono
parents:
diff changeset
2249 for Sources use ...;
kono
parents:
diff changeset
2250 end P;
kono
parents:
diff changeset
2251
kono
parents:
diff changeset
2252 To build the application you just need to call gprbuild for the
kono
parents:
diff changeset
2253 application's project, here p.gpr:
kono
parents:
diff changeset
2254
kono
parents:
diff changeset
2255 .. code-block:: sh
kono
parents:
diff changeset
2256
kono
parents:
diff changeset
2257 gprbuild p.gpr
kono
parents:
diff changeset
2258
kono
parents:
diff changeset
2259
kono
parents:
diff changeset
2260 .. _Mac_OS_Topics:
kono
parents:
diff changeset
2261
kono
parents:
diff changeset
2262 Mac OS Topics
kono
parents:
diff changeset
2263 =============
kono
parents:
diff changeset
2264
kono
parents:
diff changeset
2265 .. index:: OS X
kono
parents:
diff changeset
2266
kono
parents:
diff changeset
2267 This section describes topics that are specific to Apple's OS X
kono
parents:
diff changeset
2268 platform.
kono
parents:
diff changeset
2269
kono
parents:
diff changeset
2270 Codesigning the Debugger
kono
parents:
diff changeset
2271 ------------------------
kono
parents:
diff changeset
2272
kono
parents:
diff changeset
2273 The Darwin Kernel requires the debugger to have special permissions
kono
parents:
diff changeset
2274 before it is allowed to control other processes. These permissions
kono
parents:
diff changeset
2275 are granted by codesigning the GDB executable. Without these
kono
parents:
diff changeset
2276 permissions, the debugger will report error messages such as::
kono
parents:
diff changeset
2277
kono
parents:
diff changeset
2278 Starting program: /x/y/foo
kono
parents:
diff changeset
2279 Unable to find Mach task port for process-id 28885: (os/kern) failure (0x5).
kono
parents:
diff changeset
2280 (please check gdb is codesigned - see taskgated(8))
kono
parents:
diff changeset
2281
kono
parents:
diff changeset
2282 Codesigning requires a certificate. The following procedure explains
kono
parents:
diff changeset
2283 how to create one:
kono
parents:
diff changeset
2284
kono
parents:
diff changeset
2285 * Start the Keychain Access application (in
kono
parents:
diff changeset
2286 /Applications/Utilities/Keychain Access.app)
kono
parents:
diff changeset
2287
kono
parents:
diff changeset
2288 * Select the Keychain Access -> Certificate Assistant ->
kono
parents:
diff changeset
2289 Create a Certificate... menu
kono
parents:
diff changeset
2290
kono
parents:
diff changeset
2291 * Then:
kono
parents:
diff changeset
2292
kono
parents:
diff changeset
2293 * Choose a name for the new certificate (this procedure will use
kono
parents:
diff changeset
2294 "gdb-cert" as an example)
kono
parents:
diff changeset
2295
kono
parents:
diff changeset
2296 * Set "Identity Type" to "Self Signed Root"
kono
parents:
diff changeset
2297
kono
parents:
diff changeset
2298 * Set "Certificate Type" to "Code Signing"
kono
parents:
diff changeset
2299
kono
parents:
diff changeset
2300 * Activate the "Let me override defaults" option
kono
parents:
diff changeset
2301
kono
parents:
diff changeset
2302
kono
parents:
diff changeset
2303 * Click several times on "Continue" until the "Specify a Location
kono
parents:
diff changeset
2304 For The Certificate" screen appears, then set "Keychain" to "System"
kono
parents:
diff changeset
2305
kono
parents:
diff changeset
2306 * Click on "Continue" until the certificate is created
kono
parents:
diff changeset
2307
kono
parents:
diff changeset
2308 * Finally, in the view, double-click on the new certificate,
kono
parents:
diff changeset
2309 and set "When using this certificate" to "Always Trust"
kono
parents:
diff changeset
2310
kono
parents:
diff changeset
2311 * Exit the Keychain Access application and restart the computer
kono
parents:
diff changeset
2312 (this is unfortunately required)
kono
parents:
diff changeset
2313
kono
parents:
diff changeset
2314
kono
parents:
diff changeset
2315 Once a certificate has been created, the debugger can be codesigned
kono
parents:
diff changeset
2316 as follow. In a Terminal, run the following command:
kono
parents:
diff changeset
2317
kono
parents:
diff changeset
2318 ::
kono
parents:
diff changeset
2319
kono
parents:
diff changeset
2320 $ codesign -f -s "gdb-cert" <gnat_install_prefix>/bin/gdb
kono
parents:
diff changeset
2321
kono
parents:
diff changeset
2322 where "gdb-cert" should be replaced by the actual certificate
kono
parents:
diff changeset
2323 name chosen above, and <gnat_install_prefix> should be replaced by
kono
parents:
diff changeset
2324 the location where you installed GNAT. Also, be sure that users are
kono
parents:
diff changeset
2325 in the Unix group ``_developer``.