-
Notifications
You must be signed in to change notification settings - Fork 68
First commit of a mini-book on building programs #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great text. I wish I would read it when I started with compiled languages!
I already left some comments. I will continue the revision during the weekend.
program hello | ||
write(*,*) 'Hello!' | ||
end program hello |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All Fortran codes can be highighted with code blocks, e.g.
program hello
write(*,*) 'Hello!'
end program hello
|
||
But the basics are simple enough. Take the gfortran compiler, part of | ||
the GNU compiler collection. To compile a simple program as the one | ||
above, that consists of one source file, you run the following command: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
above, that consists of one source file, you run the following command: | |
above, that consists of one source file, you run the following command, assuming the source code is stored in the file "hello.f90": | |
|
||
$ gfortran -c hello.f90 | ||
|
||
(assuming the source code is stored in the file "hello.f90") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(assuming the source code is stored in the file "hello.f90") |
|
||
$ gfortran hello.f90 | ||
|
||
results in an executable file, "a.out" (on Linux) or "a.exe" on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
results in an executable file, "a.out" (on Linux) or "a.exe" on | |
results in an executable file, "a.out" on Linux or "a.exe" on | |
the GNU compiler collection. To compile a simple program as the one | ||
above, that consists of one source file, you run the following command: | ||
|
||
$ gfortran -c hello.f90 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like for Fortran code, code blocks can be used to highligh shell codes.
directory should come consecutively. | ||
* Many compilers allow you to specify the location for the module | ||
intermediate files. For gfortran this is "-J", for instance: | ||
-J../include (so that the .mod files could all appear in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-J../include (so that the .mod files could all appear in the | |
`-J../include` | |
(so that the .mod files could all appear in the | |
Linux and Linux-like platforms. On Windows the extension ".lib" is used. | ||
|
||
Creating your own libraries is not that complicated: you use a utility | ||
like "ar" or (on Windows) "lib" to achieve this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like "ar" or (on Windows) "lib" to achieve this: | |
like `ar` (on Linux) or `lib` (on Windows) to achieve this: | |
$ ar r supportlib.a file1.o file2.o | ||
$ ar r supportlib.a file3.o ... | ||
|
||
or, using the "link" utility: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or, using the "link" utility: | |
or, using the `link` utility: | |
|
||
Note: | ||
|
||
* The command "ar" with the option "r" either creates the library (the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The command "ar" with the option "r" either creates the library (the | |
* The command `ar` with the option `r` either creates the library (the | |
* The command "ar" with the option "r" either creates the library (the | ||
name appears after the option) or adds new object files to the library | ||
(or replaces any existing ones). | ||
* The command "lib" will create a new library if you use specify the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* The command "lib" will create a new library if you use specify the | |
* The command `lib` will create a new library if you use specify the | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great tutorial, definitely the kind of thing I needed while learning.
As Jeremie points out, the Fortran code and shell commands are best put in code blocks.
Once I finish #83, it may be a good idea to break this tutorial across multiple pages within a 'book', but for now it's good!
layout: page | ||
title: Building programs | ||
permalink: /learn/build_programs | ||
navbar: Learn |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
navbar: Learn | |
navbar: Learn | |
date: 2020-05-22 | |
author: Arjen Markus |
We can move the date and author information up to the header (it will still be displayed on site).
differences that may need to be documented. Some information would be | ||
helpful. | ||
|
||
Author: Arjen Markus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Author: Arjen Markus |
(Moved to header)
|
||
Author: Arjen Markus | ||
|
||
dd. 22 may 2020 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dd. 22 may 2020 |
(Moved to header)
/usr/lib/gcc/x86_64-pc-cygwin/9.3.0/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/9.3.0/../../../../lib/libcygwin.a(libcmain.o): in function `main': | ||
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain' | ||
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x7f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain' | ||
collect2: error: ld returned 1 exit status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/usr/lib/gcc/x86_64-pc-cygwin/9.3.0/../../../../x86_64-pc-cygwin/bin/ld: /usr/lib/gcc/x86_64-pc-cygwin/9.3.0/../../../../lib/libcygwin.a(libcmain.o): in function `main': | |
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/libcmain.c:37: undefined reference to `WinMain' | |
/usr/src/debug/cygwin-3.1.4-1/winsup/cygwin/lib/libcmain.c:37:(.text.startup+0x7f): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `WinMain' | |
collect2: error: ld returned 1 exit status | |
/usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/Scrt1.o: In function `_start': | |
(.text+0x20): undefined reference to `main' | |
collect2: error: ld returned 1 exit status |
A very minor nitpick: the cygwin environment results in an overly verbose message here.
Perhaps replace with that from Ubuntu which is more concise and bit simpler for a beginner.
* The details differ per compiler. Sometimes the "-I" option should be | ||
followed by a space and then the name of the directory, sometimes the | ||
directory should come consecutively. | ||
* Many compilers allow you to specify the location for the module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a little too ambiguous for a beginner; can you make the difference between the -I
flag and the -J
flag clearer.
i.e. that compilers place the .mod files in the current directory by default and that the -J
flag explicitly specifies an alternative location to place them (and search for them).
* As we have seen, source code that defines one or more modules, leads to | ||
so-called "module intermediate files" (with the extension ".mod"). The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* As we have seen, source code that defines one or more modules, leads to | |
so-called "module intermediate files" (with the extension ".mod"). The | |
* As we have seen, compiling source code that defines one or more modules, leads to | |
the compiler generating so-called "module intermediate files" (with the extension ".mod"). The |
Remark: I only included Linux and Windows as operating systems in this | ||
tutorial, for the simple reason that I have no experience with MacOS* | ||
in any of its guises. While MacOS* is very similar to Linux, it is the | ||
differences that may need to be documented. Some information would be | ||
helpful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remark: I only included Linux and Windows as operating systems in this | |
tutorial, for the simple reason that I have no experience with MacOS* | |
in any of its guises. While MacOS* is very similar to Linux, it is the | |
differences that may need to be documented. Some information would be | |
helpful. | |
Remark: this tutorial gives examples for the Windows and Linux operating systems, | |
however the workflow and general principles still apply to MacOS. |
It would be good if someone with experience developing on MacOS is able to check the tutorial content for any significant differences, especially with libraries.
If not, then maybe we can link to a good online resource for this?
Draft tutorial: Building programs | ||
--------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Draft tutorial: Building programs | |
--------------------------------- |
This won't be needed, the title
field in the header will be rendered first as a H1 heading.
I don't think this needs to be changed in this pull request but the Windows-specific content is presented for Cygwin, and I wonder whether the same content can be abstracted away from this environment somehow? For this tutorial it seems that Cygwin only serves to present the same Linux workflow but on Windows. Does Windows development need a separate tutorial maybe? I have no problem with Cygwin but:
(If I need to develop on Windows I now use MSYS2 because unlike WSL and Cygwin it produces truly native Windows executables) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great introduction. Cherry-pick what you want/like.
|
||
### Static versus dynamic libraries | ||
|
||
The above discussion is tacitly assuming that you are using so-called |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above discussion is tacitly assuming that you are using so-called | |
The above discussion is tacitly assuming that you are using the so-called | |
way to change the routines incorporated in the program is by rebuilding | ||
the program with a new version of the library. | ||
|
||
A flexible alternative is to use so-called dynamic libraries. These |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A flexible alternative is to use so-called dynamic libraries. These | |
A flexible alternative is to use the so-called dynamic libraries. These | |
the program with a new version of the library. | ||
|
||
A flexible alternative is to use so-called dynamic libraries. These | ||
libraries remain outside the executable program and as a consequence you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
libraries remain outside the executable program and as a consequence you | |
libraries remain outside the executable program and as a consequence | |
|
||
A flexible alternative is to use so-called dynamic libraries. These | ||
libraries remain outside the executable program and as a consequence you | ||
can replace them without rebulding the entire program. Compilers and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can replace them without rebulding the entire program. Compilers and | |
can be replaced without rebulding the entire program. Compilers and | |
libraries. You could consider dynamic libraries as a sort of executable | ||
programs that need a bit of help to be run. | ||
|
||
Building dynamic libraries works slightly differently: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Differently based on what? I have the feeling that something is missing in this sentence.
gfortran on Cygwin and Intel Fortran on Windows. In both cases | ||
we look at the tabulation program. | ||
|
||
### Cygwin and gfortran |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It could be good to replace Cygwin by GNU/Linux
* The "make" utility is a classical tool that uses instructions about | ||
how the various components of a program depend on each other to | ||
efficiently compile and link the program (or programs). It takes a | ||
so-called makefile that contains the dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so-called makefile that contains the dependencies. | |
so-called `Makefile` that contains the dependencies. | |
|
||
* Integrated development tools take care of many of the above details. A | ||
popular tool on Windows is MicroSoft's Visual Studio, but others exist, | ||
such Eclipse (Photran) and Code::Blocks. They offer a graphical |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
such Eclipse (Photran) and Code::Blocks. They offer a graphical | |
such as Eclipse (Photran) and Code::Blocks. They offer a graphical | |
Visual Studio project files via a high-level description. They abstract | ||
away from the compiler and platform specifics. | ||
|
||
Here is a very simple example of a makefile as used by the make utility, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a very simple example of a makefile as used by the make utility, | |
Here is a very simple example of a `Makefile` as used by the make utility, | |
Note: On Windows, the Intel Fortran comes with a set of _redistributable_ libraries. | ||
These will need to be made available. | ||
|
||
In general: use a tool like "ldd" or "dependency walker" to find out what |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general: use a tool like "ldd" or "dependency walker" to find out what | |
In general: use a tool like `ldd` or `dependency walker` to find out what | |
Hi Laurence,
Cygwin happens to be the easiest access I have to a Linux-like environment
(with an up-to-date gfortran installation) ;). Nothing really essential.
However, since some things simply work differently on Windows, I think it
is good to present both platforms. Actually I would like to include MacOS*
as well. But perhaps a bit more separation - present the common bits first
and then (separately?) the specifics.
Regards,
Arjen
Op za 23 mei 2020 om 13:05 schreef Laurence Kedward <
[email protected]>:
… I don't think this needs to be changed in this pull request but the
Windows-specific content is presented for *Cygwin*, and I wonder whether
the same content can be abstracted away from this environment somehow? For
this tutorial it seems that Cygwin only serves to present the same Linux
workflow but on Windows. Does Windows development need a separate tutorial
maybe?
I have no problem with Cygwin but:
- readers may not be familiar with it and;
- it is only one of multiple linux-type interfaces for Windows.
(If I need to develop on Windows I now use MSYS2 because unlike WSL and
Cygwin it produces truly native Windows executables)
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR6L7MJHD7CW7ZQC4JLRS6UV3ANCNFSM4NICRNUA>
.
|
Hi Jérémie,
thanks for the review - I will have a look and pick those cherries ;).
Regards,
Arjen
Op ma 25 mei 2020 om 18:58 schreef Jeremie Vandenplas <
[email protected]>:
… ***@***.**** commented on this pull request.
Great introduction. Cherry-pick what you want/like.
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +option "/out:" with the name of the new library next to it. To add
+object files to an existing library, leave out the "/out:" bit.
+* On platforms like Linux there is a particular convention to name
+libraries. If you name your library like "libname.a" (note the "lib"
+prefix), then you can refer to it as "-lname" in the link step.
+* Libraries are often sought in directories indicated by an option "-L"
+or "/LIBPATH". This saves you from having to specify the exact path for
+every library.
+
+Using libraries you can build very large programs without
+having to resort to extremely long command lines.
+
+
+### Static versus dynamic libraries
+
+The above discussion is tacitly assuming that you are using so-called
⬇️ Suggested change
-The above discussion is tacitly assuming that you are using so-called
+The above discussion is tacitly assuming that you are using the so-called
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +or "/LIBPATH". This saves you from having to specify the exact path for
+every library.
+
+Using libraries you can build very large programs without
+having to resort to extremely long command lines.
+
+
+### Static versus dynamic libraries
+
+The above discussion is tacitly assuming that you are using so-called
+static libraries. Static libraries (or at least parts of their
+contents) become an integral part of the executable program. The only
+way to change the routines incorporated in the program is by rebuilding
+the program with a new version of the library.
+
+A flexible alternative is to use so-called dynamic libraries. These
⬇️ Suggested change
-A flexible alternative is to use so-called dynamic libraries. These
+A flexible alternative is to use the so-called dynamic libraries. These
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +every library.
+
+Using libraries you can build very large programs without
+having to resort to extremely long command lines.
+
+
+### Static versus dynamic libraries
+
+The above discussion is tacitly assuming that you are using so-called
+static libraries. Static libraries (or at least parts of their
+contents) become an integral part of the executable program. The only
+way to change the routines incorporated in the program is by rebuilding
+the program with a new version of the library.
+
+A flexible alternative is to use so-called dynamic libraries. These
+libraries remain outside the executable program and as a consequence you
⬇️ Suggested change
-libraries remain outside the executable program and as a consequence you
+libraries remain outside the executable program and as a consequence
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +
+Using libraries you can build very large programs without
+having to resort to extremely long command lines.
+
+
+### Static versus dynamic libraries
+
+The above discussion is tacitly assuming that you are using so-called
+static libraries. Static libraries (or at least parts of their
+contents) become an integral part of the executable program. The only
+way to change the routines incorporated in the program is by rebuilding
+the program with a new version of the library.
+
+A flexible alternative is to use so-called dynamic libraries. These
+libraries remain outside the executable program and as a consequence you
+can replace them without rebulding the entire program. Compilers and
⬇️ Suggested change
-can replace them without rebulding the entire program. Compilers and
+can be replaced without rebulding the entire program. Compilers and
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +### Static versus dynamic libraries
+
+The above discussion is tacitly assuming that you are using so-called
+static libraries. Static libraries (or at least parts of their
+contents) become an integral part of the executable program. The only
+way to change the routines incorporated in the program is by rebuilding
+the program with a new version of the library.
+
+A flexible alternative is to use so-called dynamic libraries. These
+libraries remain outside the executable program and as a consequence you
+can replace them without rebulding the entire program. Compilers and
+indeed the operating system itself rely heavily on such dynamic
+libraries. You could consider dynamic libraries as a sort of executable
+programs that need a bit of help to be run.
+
+Building dynamic libraries works slightly differently:
Differently based on what? I have the feeling that something is missing in
this sentence.
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +
+Building dynamic libraries works slightly differently:
+
+On Linux:
+
+ $ gfortran -fpic -c file1.f90 file2.f90
+ $ gfortran -fpic -c file3.f90 ...
+ $ gfortran -shared --o supportlib.so file1.o file2.o file3.o ...
+
+On Windows, with the Intel Fortran compiler:
+
+ $ ifort -c file1.f90 file2.f90
+ $ ifort -c file3.f90 ...
+ $ ifort -dll -exe:supportlib.dll file1.obj file2.obj file3.obj ...
+
+The differences:
⬇️ Suggested change
-The differences:
+The differences are that:
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +
+On Linux:
+
+ $ gfortran -fpic -c file1.f90 file2.f90
+ $ gfortran -fpic -c file3.f90 ...
+ $ gfortran -shared --o supportlib.so file1.o file2.o file3.o ...
+
+On Windows, with the Intel Fortran compiler:
+
+ $ ifort -c file1.f90 file2.f90
+ $ ifort -c file3.f90 ...
+ $ ifort -dll -exe:supportlib.dll file1.obj file2.obj file3.obj ...
+
+The differences:
+
+* You need to specify a compile option on Linux, "-fpic", because the
This option is for gfortran right?It could be good to mention it
explicitely
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +On Windows, with the Intel Fortran compiler:
+
+ $ ifort -c file1.f90 file2.f90
+ $ ifort -c file3.f90 ...
+ $ ifort -dll -exe:supportlib.dll file1.obj file2.obj file3.obj ...
+
+The differences:
+
+* You need to specify a compile option on Linux, "-fpic", because the
+object code is slightly different.
+* You need to tell in the link step that you want a dynamic library (on
+Linux: a shared object/library, hence the extension ".so"; on Windows:
+a dynamic link library)
+
+There is one more thing to be aware of: On Windows you must
+explicitly specify that a routine is to be _exported_, i.e. is visible
⬇️ Suggested change
-explicitly specify that a routine is to be _exported_, i.e. is visible
+explicitly specify that a procedure is to be _exported_, i.e. is visible
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +compiler directive:
+
+ subroutine myroutine( ... )
+ !GCC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Or, with the Intel Fortran compiler:
+
+ subroutine myroutine( ... )
+ !DEC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Besides a dynamic library (DLL), a so-called import library may be
+generated.
+
+Because the details differ per compiler, here are two examples:
+gfortran on Cygwin and Intel Fortran on Windows. In both cases
+we look at the tabulation program.
⬇️ Suggested change
-we look at the tabulation program.
+we look at the `tabulation.f90` program.
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> + !GCC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Or, with the Intel Fortran compiler:
+
+ subroutine myroutine( ... )
+ !DEC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Besides a dynamic library (DLL), a so-called import library may be
+generated.
+
+Because the details differ per compiler, here are two examples:
+gfortran on Cygwin and Intel Fortran on Windows. In both cases
+we look at the tabulation program.
+
+### Cygwin and gfortran
+The "tabulate" program requires a user-defined routine "f". If we
⬇️ Suggested change
-The "tabulate" program requires a user-defined routine "f". If we
+The `tabulate` program requires a user-defined routine `f`. If we
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> + !DEC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Besides a dynamic library (DLL), a so-called import library may be
+generated.
+
+Because the details differ per compiler, here are two examples:
+gfortran on Cygwin and Intel Fortran on Windows. In both cases
+we look at the tabulation program.
+
+### Cygwin and gfortran
+The "tabulate" program requires a user-defined routine "f". If we
+let it reside in a dynamic library, say "function.dll", we can simply
+replace the implementation of the function by putting another dynamic
+library in the directory. No need to rebuild the program as such.
+
+On Cygwin it is not necessary to explicitly export a routine - all
⬇️ Suggested change
-On Cygwin it is not necessary to explicitly export a routine - all
+On Cygwin it is not necessary to explicitly export a procedure - all
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +
+Besides a dynamic library (DLL), a so-called import library may be
+generated.
+
+Because the details differ per compiler, here are two examples:
+gfortran on Cygwin and Intel Fortran on Windows. In both cases
+we look at the tabulation program.
+
+### Cygwin and gfortran
+The "tabulate" program requires a user-defined routine "f". If we
+let it reside in a dynamic library, say "function.dll", we can simply
+replace the implementation of the function by putting another dynamic
+library in the directory. No need to rebuild the program as such.
+
+On Cygwin it is not necessary to explicitly export a routine - all
+publically visible routines are exported when you build a dynamic library.
⬇️ Suggested change
-publically visible routines are exported when you build a dynamic library.
+publically visible procedures are exported when you build a dynamic library.
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +The "tabulate" program requires a user-defined routine "f". If we
+let it reside in a dynamic library, say "function.dll", we can simply
+replace the implementation of the function by putting another dynamic
+library in the directory. No need to rebuild the program as such.
+
+On Cygwin it is not necessary to explicitly export a routine - all
+publically visible routines are exported when you build a dynamic library.
+Also, no import library is generated.
+
+Since our dynamic library can be built from a single source file, we
+can take a shortcut:
+
+ $ gfortran -shared -o function.dll function.f90
+
+This produces the files "function.dll" and "function.mod". The
+utility "nm" tells us the exact name of the function "f":
⬇️ Suggested change
-utility "nm" tells us the exact name of the function "f":
+utility "nm" tells us the exact name of the function `f`:
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +
+This produces the files "function.dll" and "function.mod". The
+utility "nm" tells us the exact name of the function "f":
+
+ $ nm function.dll
+ ...
+ 000000054f9d7000 B __dynamically_loaded
+ U __end__
+ 0000000000000200 A __file_alignment__
+ 000000054f9d1030 T __function_MOD_f
+ 000000054f9d1020 T __gcc_deregister_frame
+ 000000054f9d1000 T __gcc_register_frame
+ ...
+
+It has received a prefix `__function_MOD_` to distinguish it from any
+other routine "f" that might be defined in another module.
⬇️ Suggested change
-other routine "f" that might be defined in another module.
+other procedure `f` that might be defined in another module.
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> + subroutine myroutine( ... )
+ !GCC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Or, with the Intel Fortran compiler:
+
+ subroutine myroutine( ... )
+ !DEC$ ATTRIBUTES DLLEXPORT:: myroutine
+
+Besides a dynamic library (DLL), a so-called import library may be
+generated.
+
+Because the details differ per compiler, here are two examples:
+gfortran on Cygwin and Intel Fortran on Windows. In both cases
+we look at the tabulation program.
+
+### Cygwin and gfortran
It could be good to replace Cygwin by GNU/Linux
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +
+Build tools
+-----------
+
+If this seems complicated, well, you are right and we are only
+scratching the surface here. The complications arise because of
+differences between platforms, differences between compilers/linkers and
+because of differences in the way programs are set up. Fortunately,
+there are many tools to help configure and maintain the build steps.
+We will not try and catalogue them, but give instead a very limited
+list of tools that you typically encounter:
+
+* The "make" utility is a classical tool that uses instructions about
+how the various components of a program depend on each other to
+efficiently compile and link the program (or programs). It takes a
+so-called makefile that contains the dependencies.
⬇️ Suggested change
-so-called makefile that contains the dependencies.
+so-called `Makefile` that contains the dependencies.
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +how the various components of a program depend on each other to
+efficiently compile and link the program (or programs). It takes a
+so-called makefile that contains the dependencies.
+
+ Simply put:
+
+ If a program file is older than any of the libraries and object files
+it depends on, the make utility knows it has to rebuild it and goes on
+to look at the libraries and object files - are any out of date?
+
+ If an object file is older than the corresponding source file, the
+make utility knows it has to compile the source file.
+
+* Integrated development tools take care of many of the above details. A
+popular tool on Windows is MicroSoft's Visual Studio, but others exist,
+such Eclipse (Photran) and Code::Blocks. They offer a graphical
⬇️ Suggested change
-such Eclipse (Photran) and Code::Blocks. They offer a graphical
+such as Eclipse (Photran) and Code::Blocks. They offer a graphical
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +to look at the libraries and object files - are any out of date?
+
+ If an object file is older than the corresponding source file, the
+make utility knows it has to compile the source file.
+
+* Integrated development tools take care of many of the above details. A
+popular tool on Windows is MicroSoft's Visual Studio, but others exist,
+such Eclipse (Photran) and Code::Blocks. They offer a graphical
+user-interface, but are often very specific for the compiler and
+platform.
+
+* Maintenance tools like autotools and CMake can generate makefiles or
+Visual Studio project files via a high-level description. They abstract
+away from the compiler and platform specifics.
+
+Here is a very simple example of a makefile as used by the make utility,
⬇️ Suggested change
-Here is a very simple example of a makefile as used by the make utility,
+Here is a very simple example of a `Makefile` as used by the make utility,
------------------------------
In learn/building_programs.md
<#90 (comment)>
:
> +A pre-built program that does not need to be customised, other than via its
+input, will still need to come with the various run-time libraries and will
+be specific to the operating system/environment it was built for.
+
+The set of run-time libraries differs per operating system and compiler version.
+For a freely available compiler like gfortran, the easiest thing is to ask the
+user to install that compiler on their system. In the case of Windows: the Cygwin
+environment may be called for.
+
+Alternatively, you can supply copies of the run-time libraries together with your
+program. Put them in the directory where they can be found at run-time.
+
+Note: On Windows, the Intel Fortran comes with a set of _redistributable_ libraries.
+These will need to be made available.
+
+In general: use a tool like "ldd" or "dependency walker" to find out what
⬇️ Suggested change
-In general: use a tool like "ldd" or "dependency walker" to find out what
+In general: use a tool like `ldd` or `dependency walker` to find out what
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#90 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR5BRJN56DOTBQJR35DRTKPSPANCNFSM4NICRNUA>
.
|
Just a note regarding the platform: I strongly propose that our long term goal should be to run natively on all platforms (Linux, macOS, Windows natively as well as in Cygwin and WSL, HPC, ...) using native tools where applicable. We should have some tutorial "how to get started on each platform", and how to do the basic things for each platform. That way the actual tutorial such as this PR can be written for one particular platform (Cygwin in this case) and people would know how to execute the commands on other platforms using the "how to get started on each platform" tutorial. So I think it's perfectly fine if this tutorial sticks with Cygwin. |
Hi everyone,
I plan to work through the suggestions by Jérémie tomorrow. I noticed that
the tutorial has been split into separate chapters. I can do that with this
minibook as well.
If you have more comments/suggestions, let me know.
Regards,
Arjen
Op ma 25 mei 2020 om 21:15 schreef Ondřej Čertík <[email protected]>:
… Just a note regarding the platform: I strongly propose that our long term
goal should be to run natively on all platforms (Linux, macOS, Windows
natively as well as in Cygwin and WSL, HPC, ...) using native tools where
applicable. We should have some tutorial "how to get started on each
platform", and how to do the basic things for each platform. That way the
actual tutorial such as this PR can be written for one particular platform
(Cygwin in this case) and people would know how to execute the commands on
other platforms using the ""how to get started on each platform" tutorial.
So I think it's perfectly fine if this tutorial sticks with Cygwin.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR6EHDDRNKMDLC6PIQDRTK7WRANCNFSM4NICRNUA>
.
|
Thanks for the update @arjenmarkus. |
Hi Laurence,
great - that should be helpful indeed. I was going to do it with the
tutorial's sources as an example but this is much better.
Regards,
Arjen
Op wo 3 jun. 2020 om 20:27 schreef Laurence Kedward <
[email protected]>:
… Thanks for the update @arjenmarkus <https://github.com/arjenmarkus>.
Just to let you know that there is now a guide
<https://github.com/fortran-lang/fortran-lang.org/blob/master/MINIBOOKS.md>
in the repository for how to use the new multi-page mini-book format. Do
let me know if anything isn't clear or you need further assistance.
Looking forward to seeing your mini-book published on site.
Laurence
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#90 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAN6YR46J6WYRKX3VMZRIXDRU2IZFANCNFSM4NICRNUA>
.
|
Okay, just created a new pull request for this minibook. I have tried to be
accurate wrt the mark-up and the suggested changes. A few improvements I am
thinking of:
- Clearer characterisation of the platforms
- The tabulate.f90 source should probably be revised. I have left it mostly
as it was, but the suggestions made me think a bit.
Oh, and perhaps add the source code as examples for people to work with.
Regards,
Arjen
Op do 4 jun. 2020 om 08:51 schreef Arjen Markus <[email protected]>:
… Hi Laurence,
great - that should be helpful indeed. I was going to do it with the
tutorial's sources as an example but this is much better.
Regards,
Arjen
Op wo 3 jun. 2020 om 20:27 schreef Laurence Kedward <
***@***.***>:
> Thanks for the update @arjenmarkus <https://github.com/arjenmarkus>.
> Just to let you know that there is now a guide
> <https://github.com/fortran-lang/fortran-lang.org/blob/master/MINIBOOKS.md>
> in the repository for how to use the new multi-page mini-book format. Do
> let me know if anything isn't clear or you need further assistance.
> Looking forward to seeing your mini-book published on site.
> Laurence
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#90 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AAN6YR46J6WYRKX3VMZRIXDRU2IZFANCNFSM4NICRNUA>
> .
>
|
Closing, superseded by #99. |
Please review the text: hopefully it presents the material in a clear way. IMO, the pitfall is that it presents too much details. Suggestions for changes are welcome.