Skip to content

Commit c9a9bb1

Browse files
committed
Try to improve the wording a bit
1 parent a2e41ca commit c9a9bb1

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

flang/docs/FlangDriver.md

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,18 @@ translation units supplied as object files.
172172
By default, the Flang linker driver adds several libraries to the linker
173173
invocation to make sure that all entrypoints for program start
174174
(Fortran's program unit) and runtime routines can be resolved by the linker.
175-
The libraries are:
175+
176+
An abridged example (only showing the Fortran specific linker flags, omission
177+
indicated by `[...]`) for such a linker invocation on a Linux system would look
178+
like this:
179+
180+
```
181+
$ flang -v -o example example.o
182+
"/usr/bin/ld" [...] example.o [...] "--whole-archive" "-lFortran_main"
183+
"--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" [...]
184+
```
185+
186+
The automatically added libraries are:
176187

177188
* `Fortran_main`: Provides the main entry point `main` that then invokes
178189
`_QQmain` with the Fortran program unit. This library has a dependency to
@@ -182,20 +193,25 @@ The libraries are:
182193

183194
The default is that, when using Flang as the linker, one of the Fortran
184195
translation units provides the program unit and therefore it is assumed that
185-
Fortran is the main code part (calling into C/C++ routines via `BIND
186-
(C)` interfaces). When composing the linker commandline, Flang uses
196+
Fortran is the main code part (calling into C/C++ routines via `BIND (C)`
197+
interfaces). When composing the linker commandline, Flang uses
187198
`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
188-
Darwin: *not implemented yet*) to make sure that all for `Fortran_main` is
189-
processed by the linker. This is done to issue a proper error message when
199+
Darwin & AIX: *not implemented yet*) to make sure that all for `Fortran_main`
200+
is processed by the linker. This is done to issue a proper error message when
190201
multiple definitions of `main` occur. This happens, for instance, when linking
191202
a code that has a Fortran program unit with a C/C++ code that also defines a
192-
`main` function.
193-
194-
If the code is C/C++ based and invokes Fortran routines, either use Clang as the
195-
linker driver (supplying `FortranRuntime` and/or `FortranDecimal` to the linker
196-
driver) or use Flang with the `-fno-fortran-main` flag. This flag removes
203+
`main` function. A user may be required to explicitly provide the C++ runtime
204+
libraries at link time (e.g., via `-lstdc++` for STL)
205+
206+
If the code is C/C++ based and invokes Fortran routines, one can either use Clang
207+
for Flang as the linker driver. If Clang is used, it will automatically all
208+
required runtime libraries needed by C++ (e.g., for STL) to the linker invocation.
209+
In this case, one has to explicitly provide the Fortran runtime libraries
210+
`FortranRuntime` and/or `FortranDecimal`. An alternative is to use Flang to link
211+
and use the `-fno-fortran-main` flag. This flag removes
197212
`Fortran_main` from the linker stage and hence requires one of the C/C++
198-
translation units to provide a definition of the `main` function.
213+
translation units to provide a definition of the `main` function. In this case,
214+
it may be required to explicitly supply C++ runtime libraries as mentioned above.
199215

200216
When creating shared or static libraries, `Fortran_main` is automatically
201217
removed from the linker stage. It is assumed that when creating a static or

0 commit comments

Comments
 (0)