Work in progress...
To compile with gfortran:
gcc -Wall -c libc.c -no-pie
gfortran -cpp -Wall -no-pie libc.o test_libc.f90 -o test_libc
On Linux, the flag -no-pie
is needed to generate a non-position independent executable. See the following discussions:
- 32-bit absolute addresses no longer allowed in x86-64 Linux?
- Nasm - Symbol
printf
causes overflow in R_X86_64_PC32 relocation
To compile with the Intel compilers:
icc -c libc.c
ifort -fpp -warn all libc.o test_libc.f90 -o test_libc
See the file test_libc.f90
for usage examples following those available at http://www.cplusplus.com/reference/ctime/
-
When compiled with gfortran, if
mktime
(or its Fortran wrapper) is called twice it somehow corrupts memory and issues a double free or corruption error. If the size of thetm
struct is increased from 9 to at least 11 integers, then it works properly on both compilers. See also:- Size of struct tm; The glibc version of struct tm has two additional fields
tm_gmtoff
andtm_zone
for the seconds east of UTC and the timezone abbreviation, respectively.
- Size of struct tm; The glibc version of struct tm has two additional fields
-
In some circumstances on the Fortran side the opaque pointers to the
time_t
andstruct tm
need to be declared astarget
in order to be able to callc_loc
on the internaltype(c_ptr)
variable.