# Pointer to pointer - ALLOCATE - Undefined reference

**URL:** <https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866>\
**Category:** Help\
**Created:** [December 7, 2022, 6:03am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866 "2022-12-07T06:03:57Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 6:03am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/1 "2022-12-07T06:03:57Z")

</div>

Hi,

I am currently working on a question of migration from Fortran 90 to Fortran 2003, where a pointer p1 containing itself a pointer p2 generates when calling the statement ALLOCATE the error message undefined reference for the pointer p2.

The two pointers are declared as follows:

Within the struct\_ames.f90 file:

type(p1), dimension(:), pointer::p1=\>null()

Within the p1.f90 file:

CHARACTER(LEN=50),DIMENSION(:,:),pointer:: p2=\>null()

Would you know how to solve this problem?

Thanks for your help !

---

<div class="post-metadata">

**Author:** ![gnikit](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/gnikit/32/1213_2.png) [@gnikit](https://fortran-lang.discourse.group/u/gnikit)\
**Post date:** [December 7, 2022, 7:31am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/2 "2022-12-07T07:31:27Z")

</div>

Welcome to the discourse @dev, could you post a Minimal Working Example (MWE) of your problem

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [December 7, 2022, 9:37am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/3 "2022-12-07T09:37:57Z")

</div>

We need to see more code, in particular the definition of the `p1` derived type, and the `allocate` statement that fails.

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 10:02am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/4 "2022-12-07T10:02:01Z")

</div>

Thanks for your answer.

Here are the relevant details :  
The undefined reference return is for the following statement:  
ALLOCATE(output\_ames%grids\_ames(nbfiles))

In the data structure:  
type STRUCT\_AMES  
CHARACTER(LEN=12) :: string  
type(grid\_ames), dimension(:), pointer::grids\_ames  
type(head\_ames) :: head  
end type STRUCT\_AMES

Note the declaration of the variable grids\_ames as a pointer of type grid\_ames.

The grid\_ames type itself having the pointer arrMeasurements:  
type GRID\_AMES  
CHARACTER(LEN=14) :: datemeasurement  
CHARACTER(LEN=12) :: hour  
CHARACTER(LEN=4) :: year  
CHARACTER(LEN=2) :: month  
CHARACTER(LEN=10) :: cmois  
CHARACTER(LEN=2) :: day  
CHARACTER(LEN=2) :: hour  
CHARACTER(LEN=2) :: minute  
CHARACTER(LEN=2) :: second  
REAL, DIMENSION(:,:),pointer:: arrMeasurements=\>null()  
end type GRID\_AMES

The error message obtained during compilation is as follows:  
pgf90 -o treat\_files\_list functions\_mod.o head\_ames\_mod.o grid\_ames\_mod.o struct\_ames\_mod.o lidar\_mod.o treat\_files\_list.o  
/usr/bin/ld: treat\_files\_list.o: in function `MAIN_': treat_files_list.f90:154: undefined reference to `grid\_ames\_mod\_\_\_grid\_ames\_\_td\_’  
/usr/bin/ld: treat\_files\_list.f90:154: undefined reference to `grid\_ames\_mod\_\_\_grid\_ames\_\_td\_’  
make: \*\*\* [Makefile:19: treat\_files\_list] Error 2

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [December 7, 2022, 1:25pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/5 "2022-12-07T13:25:21Z")

</div>

I tried compiling (with gfortran and ifort) and running something from these pieces of code, and didn’t encounter any error (I just had to correct a few things like the double declaration of `hour`, use an arbitrary `nbfiles`, and remove the `type(head_ames)` declaration as I don’t have the definition).

I think you really need to provide a Minimal Working Example (actually not working in your case) that reproduces the problem.

PS: please use the code formatting features (using single or triple backticks)

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 2:03pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/6 "2022-12-07T14:03:11Z")

</div>

Thanks for your answer.

Here is the detail for treat\_file\_list.f90 :

PROGRAM treat\_files\_list

USE fonctions\_mod  
USE grid\_ames\_mod  
USE head\_ames\_mod  
USE struct\_ames\_mod  
USE lidar\_mod

IMPLICIT NONE

CHARACTER(LEN=300) :: temp\_string, temp\_string2  
CHARACTER(LEN=41) :: temp\_string4  
CHARACTER(LEN=28) :: temp\_string5  
CHARACTER(LEN=14) :: temp\_string6  
CHARACTER(LEN=120) :: temp\_string80  
CHARACTER(LEN=250) :: filein,list\_files,tmp\_list  
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp\_string3  
CHARACTER(LEN=100) :: rep\_data,rep\_so,chaine,chaine2,rep\_lo,file\_lo  
CHARACTER(LEN=50) :: link  
CHARACTER(LEN=8) :: tdate  
CHARACTER(LEN=5) :: coltemp,col1  
CHARACTER(LEN=7) :: col2, col5, col6, col8  
CHARACTER(LEN=7) :: col10,col9  
CHARACTER(LEN=10) :: col11,col7  
CHARACTER(LEN=4) :: mois,annee  
CHARACTER(LEN=6) :: col4  
CHARACTER(LEN=8) :: col3  
CHARACTER(LEN=10) :: ttime  
CHARACTER(LEN=5) :: tzone  
INTEGER, DIMENSION(8) :: tvalues  
CHARACTER(LEN=200) :: screen,line,line2  
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure  
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp\_int,temp\_int2  
type(grid\_ames) :: sortie\_asc,temp\_ames  
type(struct\_ames) :: sortie\_ames  
LOGICAL :: retour  
REAL :: temp\_real

COMMON screen,rep\_so,debug  
COMMON rep\_lo,file\_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter  
call getarg(1,tmp\_list)  
nbfiles=0  
debug=1  
ifile=0

!ouverture liste des fichiers asc a traiter  
OPEN( UNIT=2, &  
FILE=tmp\_list, &  
FORM=“formatted”, &  
ACCESS=“sequential”, &  
STATUS=“old”, &  
ACTION=“read”, &  
POSITION=“rewind”, &  
IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT=‘(A)’) filein

if (ios3 /= 0 ) then  
screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))  
retour=printl()  
STOP  
endif

rep\_data=filein  
screen="DATA DIRECTORY : "//rep\_data  
retour=printl()

mois=“”  
annee=“”

READ(2,IOSTAT=ios3, FMT=‘(I)’) nbfiles  
READ(2,IOSTAT=ios3,FMT=‘(I)’) debug  
READ(2,IOSTAT=ios3,FMT=_) mois  
READ(2,IOSTAT=ios3,FMT=_) annee

!creation du fichier de sortie ames  
OPEN( UNIT=14, &  
FILE=“ohto”//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//“.anl”, &  
FORM=“formatted”, &  
ACCESS=“sequential”, &  
STATUS=“unknown”, &  
ACTION=“readwrite”, &  
POSITION=“rewind”, &  
IOSTAT=iosres )

```
    if (iosres /= 0 ) then
            screen="Impossible de creer le fichier des grilles"
            retour=printl()
            STOP
    endif

```

READ(2,IOSTAT=ios3, FMT=‘(A)’) filein

ALLOCATE(sortie\_ames%grids\_ames(nbfiles))

Actually, the compilation is allowed with pgf90 13.10 but not with pgf90 21.9.

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 3:14pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/7 "2022-12-07T15:14:41Z")

</div>

`PROGRAM treat\_files\_list

USE fonctions\_mod  
USE grid\_ames\_mod  
USE head\_ames\_mod  
USE struct\_ames\_mod  
USE lidar\_mod

IMPLICIT NONE

CHARACTER(LEN=300) :: temp\_string, temp\_string2  
CHARACTER(LEN=41) :: temp\_string4  
CHARACTER(LEN=28) :: temp\_string5  
CHARACTER(LEN=14) :: temp\_string6  
CHARACTER(LEN=120) :: temp\_string80  
CHARACTER(LEN=250) :: filein,list\_files,tmp\_list  
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp\_string3  
CHARACTER(LEN=100) :: rep\_data,rep\_so,chaine,chaine2,rep\_lo,file\_lo  
CHARACTER(LEN=50) :: link  
CHARACTER(LEN=8) :: tdate  
CHARACTER(LEN=5) :: coltemp,col1  
CHARACTER(LEN=7) :: col2, col5, col6, col8  
CHARACTER(LEN=7) :: col10,col9  
CHARACTER(LEN=10) :: col11,col7  
CHARACTER(LEN=4) :: mois,annee  
CHARACTER(LEN=6) :: col4  
CHARACTER(LEN=8) :: col3  
CHARACTER(LEN=10) :: ttime  
CHARACTER(LEN=5) :: tzone  
INTEGER, DIMENSION(8) :: tvalues  
CHARACTER(LEN=200) :: screen,line,line2  
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure  
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp\_int,temp\_int2  
type(grid\_ames) :: sortie\_asc,temp\_ames  
type(struct\_ames) :: sortie\_ames  
LOGICAL :: retour  
REAL :: temp\_real

COMMON screen,rep\_so,debug  
COMMON rep\_lo,file\_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter  
call getarg(1,tmp\_list)  
nbfiles=0  
debug=1  
ifile=0

!ouverture liste des fichiers asc a traiter  
OPEN( UNIT=2, &  
FILE=tmp\_list, &  
FORM=“formatted”, &  
ACCESS=“sequential”, &  
STATUS=“old”, &  
ACTION=“read”, &  
POSITION=“rewind”, &  
IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT=‘(A)’) filein

if (ios3 /= 0 ) then  
screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))  
retour=printl()  
STOP  
endif

rep\_data=filein  
screen="DATA DIRECTORY : "//rep\_data  
retour=printl()

mois=“”  
annee=“”

READ(2,IOSTAT=ios3, FMT=‘(I)’) nbfiles  
READ(2,IOSTAT=ios3,FMT=‘(I)’) debug  
READ(2,IOSTAT=ios3,FMT=_) mois  
READ(2,IOSTAT=ios3,FMT=_) annee

!creation du fichier de sortie ames  
OPEN( UNIT=14, &  
FILE=“ohto”//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//“.anl”, &  
FORM=“formatted”, &  
ACCESS=“sequential”, &  
STATUS=“unknown”, &  
ACTION=“readwrite”, &  
POSITION=“rewind”, &  
IOSTAT=iosres )

```
    if (iosres /= 0 ) then
            screen="Impossible de creer le fichier des grilles"
            retour=printl()
            STOP
    endif

```

READ(2,IOSTAT=ios3, FMT=‘(A)’) filein

ALLOCATE(sortie\_ames%grids\_ames(nbfiles))`

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 3:16pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/8 "2022-12-07T15:16:14Z")

</div>

Actually compiling is working with pgf90 13.10 but not pgf90 21.9 :

````nohighlight

USE fonctions_mod 
USE grid_ames_mod
USE head_ames_mod
USE struct_ames_mod
USE lidar_mod

IMPLICIT NONE

CHARACTER(LEN=300) :: temp_string, temp_string2
CHARACTER(LEN=41) :: temp_string4
CHARACTER(LEN=28) :: temp_string5
CHARACTER(LEN=14) :: temp_string6
CHARACTER(LEN=120) :: temp_string80
CHARACTER(LEN=250) :: filein,list_files,tmp_list
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp_string3
CHARACTER(LEN=100) :: rep_data,rep_so,chaine,chaine2,rep_lo,file_lo
CHARACTER(LEN=50) :: link
CHARACTER(LEN=8) :: tdate
CHARACTER(LEN=5) :: coltemp,col1
CHARACTER(LEN=7) :: col2, col5, col6, col8
CHARACTER(LEN=7) :: col10,col9
CHARACTER(LEN=10) :: col11,col7
CHARACTER(LEN=4) :: mois,annee
CHARACTER(LEN=6) :: col4 
CHARACTER(LEN=8) :: col3 
CHARACTER(LEN=10) :: ttime
CHARACTER(LEN=5) :: tzone
INTEGER, DIMENSION(8) :: tvalues
CHARACTER(LEN=200) :: screen,line,line2 
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp_int,temp_int2
type(grid_ames) :: sortie_asc,temp_ames
type(struct_ames) :: sortie_ames
LOGICAL :: retour
REAL :: temp_real

COMMON screen,rep_so,debug
COMMON rep_lo,file_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter
call getarg(1,tmp_list)
nbfiles=0
debug=1
ifile=0

!ouverture liste des fichiers asc a traiter
OPEN( UNIT=2, &
        FILE=tmp_list, &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="old", &
        ACTION="read", &
        POSITION="rewind", &
        IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT='(A)') filein 

if (ios3 /= 0 ) then
	screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))
        retour=printl()
        STOP
endif

rep_data=filein
screen="DATA DIRECTORY : "//rep_data
retour=printl()

mois=""
annee=""

READ(2,IOSTAT=ios3, FMT='(I)') nbfiles
READ(2,IOSTAT=ios3,FMT='(I)') debug
READ(2,IOSTAT=ios3,FMT=*) mois 
READ(2,IOSTAT=ios3,FMT=*) annee

!creation du fichier de sortie ames
OPEN( UNIT=14, &
        FILE="ohto"//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//".anl", &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="unknown", &
        ACTION="readwrite", &
        POSITION="rewind", &
        IOSTAT=iosres )

        if (iosres /= 0 ) then
                screen="Impossible de creer le fichier des grilles"
                retour=printl()
                STOP
        endif

READ(2,IOSTAT=ios3, FMT='(A)') filein

ALLOCATE(sortie_ames%grids_ames(nbfiles))```
````

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 3:18pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/9 "2022-12-07T15:18:51Z")

</div>

Actually compiling is working with pgf90 13.10 but not pgf90 21.9.

````nohighlight

USE fonctions_mod 
USE grid_ames_mod
USE head_ames_mod
USE struct_ames_mod
USE lidar_mod

IMPLICIT NONE

CHARACTER(LEN=300) :: temp_string, temp_string2
CHARACTER(LEN=41) :: temp_string4
CHARACTER(LEN=28) :: temp_string5
CHARACTER(LEN=14) :: temp_string6
CHARACTER(LEN=120) :: temp_string80
CHARACTER(LEN=250) :: filein,list_files,tmp_list
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp_string3
CHARACTER(LEN=100) :: rep_data,rep_so,chaine,chaine2,rep_lo,file_lo
CHARACTER(LEN=50) :: link
CHARACTER(LEN=8) :: tdate
CHARACTER(LEN=5) :: coltemp,col1
CHARACTER(LEN=7) :: col2, col5, col6, col8
CHARACTER(LEN=7) :: col10,col9
CHARACTER(LEN=10) :: col11,col7
CHARACTER(LEN=4) :: mois,annee
CHARACTER(LEN=6) :: col4 
CHARACTER(LEN=8) :: col3 
CHARACTER(LEN=10) :: ttime
CHARACTER(LEN=5) :: tzone
INTEGER, DIMENSION(8) :: tvalues
CHARACTER(LEN=200) :: screen,line,line2 
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp_int,temp_int2
type(grid_ames) :: sortie_asc,temp_ames
type(struct_ames) :: sortie_ames
LOGICAL :: retour
REAL :: temp_real

COMMON screen,rep_so,debug
COMMON rep_lo,file_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter
call getarg(1,tmp_list)
nbfiles=0
debug=1
ifile=0

!ouverture liste des fichiers asc a traiter
OPEN( UNIT=2, &
        FILE=tmp_list, &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="old", &
        ACTION="read", &
        POSITION="rewind", &
        IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT='(A)') filein 

if (ios3 /= 0 ) then
	screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))
        retour=printl()
        STOP
endif

rep_data=filein
screen="DATA DIRECTORY : "//rep_data
retour=printl()

mois=""
annee=""

READ(2,IOSTAT=ios3, FMT='(I)') nbfiles
READ(2,IOSTAT=ios3,FMT='(I)') debug
READ(2,IOSTAT=ios3,FMT=*) mois 
READ(2,IOSTAT=ios3,FMT=*) annee

!creation du fichier de sortie ames
OPEN( UNIT=14, &
        FILE="ohto"//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//".anl", &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="unknown", &
        ACTION="readwrite", &
        POSITION="rewind", &
        IOSTAT=iosres )

        if (iosres /= 0 ) then
                screen="Impossible de creer le fichier des grilles"
                retour=printl()
                STOP
        endif

READ(2,IOSTAT=ios3, FMT='(A)') filein

ALLOCATE(sortie_ames%grids_ames(nbfiles))```
````

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 3:41pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/11 "2022-12-07T15:41:13Z")

</div>

PROGRAM treat\_files\_list

USE fonctions\_mod  
USE grid\_ames\_mod  
USE head\_ames\_mod  
USE struct\_ames\_mod  
USE lidar\_mod

IMPLICIT NONE

CHARACTER(LEN=300) :: temp\_string, temp\_string2  
CHARACTER(LEN=41) :: temp\_string4  
CHARACTER(LEN=28) :: temp\_string5  
CHARACTER(LEN=14) :: temp\_string6  
CHARACTER(LEN=120) :: temp\_string80  
CHARACTER(LEN=250) :: filein,list\_files,tmp\_list  
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp\_string3  
CHARACTER(LEN=100) :: rep\_data,rep\_so,chaine,chaine2,rep\_lo,file\_lo  
CHARACTER(LEN=50) :: link  
CHARACTER(LEN=8) :: tdate  
CHARACTER(LEN=5) :: coltemp,col1  
CHARACTER(LEN=7) :: col2, col5, col6, col8  
CHARACTER(LEN=7) :: col10,col9  
CHARACTER(LEN=10) :: col11,col7  
CHARACTER(LEN=4) :: mois,annee  
CHARACTER(LEN=6) :: col4  
CHARACTER(LEN=8) :: col3  
CHARACTER(LEN=10) :: ttime  
CHARACTER(LEN=5) :: tzone  
INTEGER, DIMENSION(8) :: tvalues  
CHARACTER(LEN=200) :: screen,line,line2  
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure  
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp\_int,temp\_int2  
type(grid\_ames) :: sortie\_asc,temp\_ames  
type(struct\_ames) :: sortie\_ames  
LOGICAL :: retour  
REAL :: temp\_real

COMMON screen,rep\_so,debug  
COMMON rep\_lo,file\_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter  
call getarg(1,tmp\_list)  
nbfiles=0  
debug=1  
ifile=0

!ouverture liste des fichiers asc a traiter  
OPEN( UNIT=2, &  
FILE=tmp\_list, &  
FORM=“formatted”, &  
ACCESS=“sequential”, &  
STATUS=“old”, &  
ACTION=“read”, &  
POSITION=“rewind”, &  
IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT=‘(A)’) filein

if (ios3 /= 0 ) then  
screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))  
retour=printl()  
STOP  
endif

rep\_data=filein  
screen="DATA DIRECTORY : "//rep\_data  
retour=printl()

mois=“”  
annee=“”

READ(2,IOSTAT=ios3, FMT=‘(I)’) nbfiles  
READ(2,IOSTAT=ios3,FMT=‘(I)’) debug  
READ(2,IOSTAT=ios3,FMT=_) mois  
READ(2,IOSTAT=ios3,FMT=_) annee

!creation du fichier de sortie ames  
OPEN( UNIT=14, &  
FILE=“ohto”//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//“.anl”, &  
FORM=“formatted”, &  
ACCESS=“sequential”, &  
STATUS=“unknown”, &  
ACTION=“readwrite”, &  
POSITION=“rewind”, &  
IOSTAT=iosres )

```
    if (iosres /= 0 ) then
            screen="Impossible de creer le fichier des grilles"
            retour=printl()
            STOP
    endif

```

READ(2,IOSTAT=ios3, FMT=‘(A)’) filein

ALLOCATE(sortie\_ames%grids\_ames(nbfiles))

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 7, 2022, 3:41pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/12 "2022-12-07T15:41:54Z")

</div>

```auto
PROGRAM treat_files_list

USE fonctions_mod 
USE grid_ames_mod
USE head_ames_mod
USE struct_ames_mod
USE lidar_mod

IMPLICIT NONE

CHARACTER(LEN=300) :: temp_string, temp_string2
CHARACTER(LEN=41) :: temp_string4
CHARACTER(LEN=28) :: temp_string5
CHARACTER(LEN=14) :: temp_string6
CHARACTER(LEN=120) :: temp_string80
CHARACTER(LEN=250) :: filein,list_files,tmp_list
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp_string3
CHARACTER(LEN=100) :: rep_data,rep_so,chaine,chaine2,rep_lo,file_lo
CHARACTER(LEN=50) :: link
CHARACTER(LEN=8) :: tdate
CHARACTER(LEN=5) :: coltemp,col1
CHARACTER(LEN=7) :: col2, col5, col6, col8
CHARACTER(LEN=7) :: col10,col9
CHARACTER(LEN=10) :: col11,col7
CHARACTER(LEN=4) :: mois,annee
CHARACTER(LEN=6) :: col4 
CHARACTER(LEN=8) :: col3 
CHARACTER(LEN=10) :: ttime
CHARACTER(LEN=5) :: tzone
INTEGER, DIMENSION(8) :: tvalues
CHARACTER(LEN=200) :: screen,line,line2 
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp_int,temp_int2
type(grid_ames) :: sortie_asc,temp_ames
type(struct_ames) :: sortie_ames
LOGICAL :: retour
REAL :: temp_real

COMMON screen,rep_so,debug
COMMON rep_lo,file_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter
call getarg(1,tmp_list)
nbfiles=0
debug=1
ifile=0

!ouverture liste des fichiers asc a traiter
OPEN( UNIT=2, &
        FILE=tmp_list, &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="old", &
        ACTION="read", &
        POSITION="rewind", &
        IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT='(A)') filein 

if (ios3 /= 0 ) then
	screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))
        retour=printl()
        STOP
endif

rep_data=filein
screen="DATA DIRECTORY : "//rep_data
retour=printl()

mois=""
annee=""

READ(2,IOSTAT=ios3, FMT='(I)') nbfiles
READ(2,IOSTAT=ios3,FMT='(I)') debug
READ(2,IOSTAT=ios3,FMT=*) mois 
READ(2,IOSTAT=ios3,FMT=*) annee

!creation du fichier de sortie ames
OPEN( UNIT=14, &
        FILE="ohto"//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//".anl", &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="unknown", &
        ACTION="readwrite", &
        POSITION="rewind", &
        IOSTAT=iosres )

        if (iosres /= 0 ) then
                screen="Impossible de creer le fichier des grilles"
                retour=printl()
                STOP
        endif

READ(2,IOSTAT=ios3, FMT='(A)') filein

ALLOCATE(sortie_ames%grids_ames(nbfiles))

```

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [December 7, 2022, 6:08pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/13 "2022-12-07T18:08:52Z")

</div>

Where is `grid_ames` type defined? In a module? Is `grid_ames_mod.o` file a compiled version of that module? I am asking because, as @PierU have noticed, the code of `type grid_ames` contains an error (component `hour` defined twice), so I wander how were you able to create `.o` file

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 8, 2022, 8:20am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/14 "2022-12-08T08:20:11Z")

</div>

Here is the code for grid\_ames\_mod.f90.  
The double definition of the time was related to a translation error from google translate.

```auto
MODULE grid_ames_mod 

IMPLICIT NONE

CONTAINS

type GRID_AMES
	CHARACTER(LEN=14) :: datemesure
	CHARACTER(LEN=4) :: annee
	CHARACTER(LEN=4) :: yearmes 
	CHARACTER(LEN=10) :: monthmes 
	CHARACTER(LEN=10) :: cmois 
	CHARACTER(LEN=10) :: cheure 
	CHARACTER(LEN=2) :: daymes 
	CHARACTER(LEN=2) :: deb_heuremes 
	CHARACTER(LEN=2) :: deb_minutemes 
	CHARACTER(LEN=2) :: deb_secondemes 
	CHARACTER(LEN=2) :: fin_heuremes
        CHARACTER(LEN=2) :: fin_minutemes
        CHARACTER(LEN=2) :: fin_secondemes
	CHARACTER(LEN=10) :: dureemes		
	CHARACTER(LEN=10) :: julianday 
	CHARACTER(LEN=10) :: deb_alt 
	CHARACTER(LEN=10),DIMENSION(15) :: top	
	CHARACTER(LEN=50),DIMENSION(:,:),pointer	:: tabMesures=>null()
	CHARACTER(LEN=10) :: v_resolution
        CHARACTER(LEN=10) :: wave_length
        CHARACTER(LEN=10) :: nb_shot
        CHARACTER(LEN=10) :: frequency
end type GRID_AMES

END MODULE grid_ames_mod 

```

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [December 8, 2022, 6:28pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/15 "2022-12-08T18:28:25Z")

</div>

Still, it is not compilable, you cannot put a definition of type after `CONTAINS`

```nohighlight
$ gfortran -c grid_ames_mod.f90 
grid_ames_mod.f90:7:14:

    7 | type GRID_AMES
      | 1
Error: Unexpected derived type declaration statement in CONTAINS section at (1)

```

Even after commenting out `CONTAINS` line and compiling the module, the main program fails to compile in many places, partly due to absence of other modules `USE`d (struct\_ames) but also due to non-standard use of format `(I)` without any width. The `ALLOCATE` statement that you complain about cannot be checked as it operates on `sortie_ames` object, defined as `type(struct_ames) :: sortie_ames`, and we still do not have the module.

So, to summarize, you have still not given a MWE, Minimal Working Example, here to be interpreted as the minimal bunch of code of which the **only** problem to compile is the `ALLOCATE` statement.

---

<div class="post-metadata">

**Author:** ![everythingfunctional](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/everythingfunctional/32/176_2.png) [@everythingfunctional](https://fortran-lang.discourse.group/u/everythingfunctional)\
**Post date:** [December 8, 2022, 6:38pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/16 "2022-12-08T18:38:17Z")

</div>

I’m going to take a wild guess here and suggest that the error is a run-time error, not a compile-time error, and that upon executing the line

> [@dev](#):
>
> ALLOCATE(output\_ames%grids\_ames(nbfiles))

The variable `output_ames` is itself a pointer or allocatable, and has not been allocated. Thus simply referencing the component `grids_ames`, let alone trying to allocate, is invalid.

FYI, copy pasting the exact error message would make things easier for everybody.

---

<div class="post-metadata">

**Author:** ![msz59](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@msz59](https://fortran-lang.discourse.group/u/msz59)\
**Post date:** [December 8, 2022, 7:42pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/17 "2022-12-08T19:42:19Z")

</div>

The OP cited upthread an error during compilation, but maybe it was while trying to prepare a MWE, not the original code.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [December 9, 2022, 9:43am UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/18 "2022-12-09T09:43:28Z")

</div>

@everythingfunctional `output_ames` is also named `sortie_ames` before translation, and the latter is not defined as a pointer. Anyway, without a MWE we can indeed just guess…

---

<div class="post-metadata">

**Author:** ![dev](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@dev](https://fortran-lang.discourse.group/u/dev)\
**Post date:** [December 9, 2022, 4:43pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/19 "2022-12-09T16:43:04Z")

</div>

Thanks for these explanations.

Here is a MWE :

**Module treat\_files\_list.f90 :**

```auto
PROGRAM treat_files_list
 
USE grid_ames_mod 
USE struct_ames_mod 

IMPLICIT NONE

CHARACTER(LEN=300) :: temp_string, temp_string2
CHARACTER(LEN=41) :: temp_string4
CHARACTER(LEN=28) :: temp_string5
CHARACTER(LEN=14) :: temp_string6
CHARACTER(LEN=120) :: temp_string80
CHARACTER(LEN=250) :: filein,list_files,tmp_list
CHARACTER(LEN=100) :: cmoismin,cmoismax,cheuremin,cheuremax ,temp_string3
CHARACTER(LEN=100) :: rep_data,rep_so,chaine,chaine2,rep_lo,file_lo
CHARACTER(LEN=50) :: link
CHARACTER(LEN=8) :: tdate
CHARACTER(LEN=5) :: coltemp,col1
CHARACTER(LEN=7) :: col2, col5, col6, col8
CHARACTER(LEN=7) :: col10,col9
CHARACTER(LEN=10) :: col11,col7
CHARACTER(LEN=4) :: mois,annee
CHARACTER(LEN=6) :: col4 
CHARACTER(LEN=8) :: col3 
CHARACTER(LEN=10) :: ttime
CHARACTER(LEN=5) :: tzone
INTEGER, DIMENSION(8) :: tvalues
CHARACTER(LEN=200) :: screen,line,line2 
INTEGER :: i,j,indice,idatemesure,idatemesuremax,idatemesuremin,nblcomment,ifdatemesure
INTEGER :: unit,ios,ios2,iosres,debug,nbfile,ios3,lecture,ulog,nbfiles,ifile,temp_int,temp_int2
type(grid_ames) :: sortie_asc,temp_ames
type(struct_ames) :: sortie_ames
LOGICAL :: retour
REAL :: temp_real

COMMON screen,rep_so,debug
COMMON rep_lo,file_lo,ulog

!lecture du fichier temporaire devant contenir la liste des fichiers de donnees a traiter
call getarg(1,tmp_list)
nbfiles=0
debug=1
ifile=0

!ouverture liste des fichiers asc a traiter
OPEN( UNIT=2, &
        FILE=tmp_list, &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="old", &
        ACTION="read", &
        POSITION="rewind", &
        IOSTAT=ios3 )

READ(2,IOSTAT=ios3, FMT='(A)') filein 

if (ios3 /= 0 ) then
	screen="Impossible d ouvrir le fichier temporaire des fichiers de donnees a traiter : "//adjustl(trim(filein))
        retour=printl()
        STOP
endif

rep_data=filein
screen="DATA DIRECTORY : "//rep_data
retour=printl()

mois=""
annee=""

READ(2,IOSTAT=ios3, FMT='(I)') nbfiles
READ(2,IOSTAT=ios3,FMT='(I)') debug
READ(2,IOSTAT=ios3,FMT=*) mois 
READ(2,IOSTAT=ios3,FMT=*) annee

!creation du fichier de sortie ames
OPEN( UNIT=14, &
        FILE="ohto"//trim(adjustl(annee(3:4)))//trim(adjustl(mois))//".anl", &
        FORM="formatted", &
        ACCESS="sequential", &
        STATUS="unknown", &
        ACTION="readwrite", &
        POSITION="rewind", &
        IOSTAT=iosres )

        if (iosres /= 0 ) then
                screen="Impossible de creer le fichier des grilles"
                retour=printl()
                STOP
        endif

READ(2,IOSTAT=ios3, FMT='(A)') filein

ALLOCATE(sortie_ames%grids_ames(nbfiles))

```

**Module grid\_ames\_mod.f90**

```auto
MODULE grid_ames_mod

IMPLICIT NONE

CONTAINS

type GRID_AMES
	CHARACTER(LEN=14) :: datemesure
	CHARACTER(LEN=4) :: annee
	CHARACTER(LEN=4) :: yearmes 
	CHARACTER(LEN=10) :: monthmes 
	CHARACTER(LEN=10) :: cmois 
	CHARACTER(LEN=10) :: cheure 
	CHARACTER(LEN=2) :: daymes 
	CHARACTER(LEN=2) :: deb_heuremes 
	CHARACTER(LEN=2) :: deb_minutemes 
	CHARACTER(LEN=2) :: deb_secondemes 
	CHARACTER(LEN=2) :: fin_heuremes
        CHARACTER(LEN=2) :: fin_minutemes
        CHARACTER(LEN=2) :: fin_secondemes
	CHARACTER(LEN=10) :: dureemes		
	CHARACTER(LEN=10) :: julianday 
	CHARACTER(LEN=10) :: deb_alt 
	CHARACTER(LEN=10),DIMENSION(15) :: top	
	CHARACTER(LEN=50),DIMENSION(:,:),pointer	:: tabMesures=>null()
	CHARACTER(LEN=10) :: v_resolution
        CHARACTER(LEN=10) :: wave_length
        CHARACTER(LEN=10) :: nb_shot
        CHARACTER(LEN=10) :: frequency
end type GRID_AMES

END MODULE grid_ames_mod 

```

**Module head\_ames\_mod.f90**

```auto
MODULE head_ames_mod 

IMPLICIT NONE

CONTAINS

type HEAD_AMES

	CHARACTER(LEN=12) :: station
        CHARACTER(LEN=12) :: instrument
        CHARACTER(LEN=40) :: instrument2
        CHARACTER(LEN=20) :: pi
        CHARACTER(LEN=40) :: pi2
        CHARACTER(LEN=12) :: specie
        CHARACTER(LEN=100) :: date
	CHARACTER(LEN=50) :: datemin, datemax
        CHARACTER(LEN=100) :: lab
        CHARACTER(LEN=100) :: head_line
        INTEGER :: julianday 
	CHARACTER(LEN=5) :: altitude
	CHARACTER(LEN=5) :: latitude 
	CHARACTER(LEN=5) :: longitude 

end type HEAD_AMES

END MODULE head_ames_mod 

```

**Module struct\_ames\_mod.f90**

```auto
MODULE struct_ames_mod 

IMPLICIT NONE

CONTAINS
USE head_ames_mod
USE grid_ames_mod

type STRUCT_AMES
	CHARACTER(LEN=12) :: chaine 
	type(grid_ames),DIMENSION(:),pointer :: grids_ames=>null()	
	type(head_ames) :: head	 	

end type STRUCT_AMES

END MODULE struct_ames_mod 

```

**Makefile**

```auto
#!/bin/bash

OBJ = head_ames_mod.o grid_ames_mod.o struct_ames_mod.o treat_files_list.o
FC = pgf90
FLAGS =
.SUFFIXES : .f90
all:	treat_files_list    
clean:
	rm -f *.o *.mod
.f90.o:
	$(FC) $(FLAGS) -c head_ames_mod.f90
	$(FC) $(FLAGS) -c grid_ames_mod.f90
	$(FC) $(FLAGS) -c struct_ames_mod.f90  
	$(FC) $(FLAGS) -c treat_files_list.f90

treat_files_list: $(OBJ)
	$(FC) -o treat_files_list $(OBJ) 

```

**Working compilation :**  
pgf90 --version  
pgf90 13.10-0 64-bit target on x86-64 Linux -tp sandybridge  
The Portland Group - PGI Compilers and Tools  
Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.

**Not working compilation**  
pgf90 --version  
pgf90 (aka nvfortran) 21.9-0 64-bit target on x86-64 Linux -tp zen  
PGI Compilers and Tools  
Copyright (c) 2021, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

**Error message**  
vFortran$ make  
pgf90 -c head\_ames\_mod.f90  
pgf90 -c grid\_ames\_mod.f90  
pgf90 -c struct\_ames\_mod.f90  
pgf90 -c treat\_files\_list.f90  
pgf90 -o treat\_files\_list head\_ames\_mod.o grid\_ames\_mod.o struct\_ames\_mod.o treat\_files\_list.o  
/usr/bin/ld: treat\_files\_list.o: in function `MAIN_': vFortran/treat_files_list.f90:154: undefined reference to `grid\_ames\_mod\_\_\_grid\_ames\_\_td\_’  
/usr/bin/ld: vFortran/treat\_files\_list.f90:154: undefined reference to `grid\_ames\_mod\_\_\_grid\_ames\_\_td\_’  
make: \*\*\* [Makefile:19: treat\_files\_list] Error 2

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [December 9, 2022, 9:19pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/20 "2022-12-09T21:19:24Z")

</div>

This is still not a MWE, I had to correct many errors before be able to compile it: there are type definitions after `contains` statements (I removed the `contains`), `FMT='(I)'` misses a length (modified to `FMT='(I10)'`), there are `USE` statements after `IMPLICIT NONE`, `END PROGRAM` is missing, and the `printl()` function is not defined.

At the end I could compile (with gfortran-12)… without the error you are encountering: I could build an executable. But again this is not concluding, as this is clearly not a code that you have compiled…

Note that your error is at link time, not at compile time.

A guess: your main program has two `USE` statements, one for `grid_ames_mod` and one for `struct_ames_mod`. But `grid_ames_mod` is already used by `grid_ames_mod` and is hence seen twice by the main program: gfortran does complain about that, but maybe pfg 21 is confused. Try commenting `USE grid_ames_mod` in the main program.

---

<div class="post-metadata">

**Author:** ![RonShepard](https://avatars.discourse-cdn.com/v4/letter/r/a3d4f5/32.png) [@RonShepard](https://fortran-lang.discourse.group/u/RonShepard)\
**Post date:** [December 10, 2022, 4:38pm UTC](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866/21 "2022-12-10T16:38:36Z")

</div>

> [@PierU](#):
>
> But `grid_ames_mod` is already used by `grid_ames_mod` and is hence seen twice by the main program:

That is something that occurs all the time in fortran, and it should not be a problem. Modules in fortran are designed to allow that without the compiler being confused. Is there something special in this code that does cause a compiler to be confused?

[Next page](https://fortran-lang.discourse.group/t/pointer-to-pointer-allocate-undefined-reference/4866.md?page=2)
