Skip to content

Compilation success or fail depending on the order of inclusion of fortran_stdlib_... #1193

Description

@wfgvanrooijen

I am learning to use fortran_stdlib. I encountered an issue that took me hours to resolve and I wonder whether this is a bug or a feature.

Details:

  • Ubuntu Linux 24.04.4
  • Compiler: gfortran 13.3.0
  • I compiled fortran_stdlib following the instructions on GitHub; all tests passed.

Please refer to the minimal working example below:

program stdlib_norm_mwe↲                                                        
use stdlib_linalg, only: norm↲                                                                                   
use stdlib_math, only: deg2rad↲                                                 
use stdlib_ascii, only: to_upper↲                                               
implicit none↲                                                                  
real, dimension(3) :: v↲                                                        
character(len=1) :: c↲                                                          
real :: theta↲                                                                  
theta = 45.0↲                                                                   
c = 'a'↲                                                                        
v = [1.0, 2.0, 3.0]↲                                                            
print *, v, norm(v, 2)↲                                                         
print *, c, " -> to_upper() ->", to_upper(c)↲                                                                    
print *, theta, deg2rad(theta)↲                                                 
print *, "success"↲                                                             
end program stdlib_norm_mwe↲    

Compilation steps:
Step 1: gfortran -c stdlib_norm_mwe.f90 -I /usr/local/include/fortran_stdlib/GNU-13.3.0/

Step 2a (notice that fortran_stdlib_core is now the LAST library to be included): gfortran -o stdlib_norm_mwe stdlib_norm_mwe.o -L /usr/local/lib/ -lfortran_stdlib_linalg -lfortran_stdlib_linalg_core -lfortran_stdlib_lapack -lfortran_stdlib_blas -lfortran_stdlib_math -lfortran_stdlib_core

This is compiles without warning and the resulting program functions correctly.

Step 2b (notice that fortran_stdlib_core is now the FIRST library to be included): gfortran -o stdlib_norm_mwe stdlib_norm_mwe.o -L /usr/local/lib/ -lfortran_stdlib_core -lfortran_stdlib_linalg -lfortran_stdlib_linalg_core -lfortran_stdlib_lapack -lfortran_stdlib_blas -lfortran_stdlib_math

This fails with many messages. The last few lines are:

stdlib_linalg_lapack_aux.f90:(.text+0xaa23): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xaa9c): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xab15): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xac53): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xaccc): undefined reference to `__stdlib_error_MOD___vtab_INTEGER_4_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xae06): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xae7f): undefined reference to `__stdlib_error_MOD___vtab_INTEGER_4_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xaef8): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xaf71): undefined reference to `__stdlib_error_MOD___vtab_INTEGER_4_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xb0b5): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xb12e): undefined reference to `__stdlib_error_MOD___vtab_INTEGER_4_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xb1a7): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' /usr/bin/ld: stdlib_linalg_lapack_aux.f90:(.text+0xb2e5): undefined reference to `__stdlib_error_MOD___vtab_CHARACTER_1_' collect2: error: ld returned 1 exit status

In my experience, the order of inclusion of the libraries on the command line should not make a difference, but in this case, it does. I don't know whether this is a bug or a feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions