fortran-lang / fpm

Fortran Package Manager (fpm)
https://fpm.fortran-lang.org
MIT License
844 stars 95 forks source link

ordering of link flags before archive, thus flag ignored by linker #1015

Open scivision opened 2 months ago

scivision commented 2 months ago

Description

The link flags are put before the archive in the command line, causing the link flags to be ignored by the linker (at least for GCC).

With at least FPM 0.10.0 and 0.10.1, regardless of operating system (Linux and Windows tried), and using Ffilesystem project (probably any project has this issue):

by either:

FPM_LDFLAGS=-lm fpm build

or

fpm build --link-flags "-lm"

results in command:

Windows:

gfortran    -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -fimplicit-none -Werror=implicit-interface -I.\.\include  -lm build\gfortran_CCDA9AB199436CCD\ffilesystem\app_fortran_main.f90.o build\gfortran_A18F5477E168D1CF\ffilesystem\libffilesystem.a -lstdc++ -o build\gfortran_E885EEFD2DC7A74C\app\main.exe

Linux:

gfortran    -Wall -Wextra -fPIC -fmax-errors=1 -g -fcheck=bounds -fcheck=array-temps -fbacktrace -fcoarray=single -fimplicit-none -Werror=implicit-interface -I././include  -lm build/gfortran_E17BCF1508095BB1/ffilesystem/app_fortran_main.f90.o build/gfortran_FA0A528919A6C0C3/ffilesystem/libffilesystem.a -lstdc++ -o build/gfortran_6A2ED2947B09C891/app/main

Expected Behaviour

I expect the link flag "-lm" (or say -lUserenv for Windows) to be AFTER the object file or archive, otherwise the linker ignores the link flag

Version of fpm

0.10.1, 0.10.0

Platform and Architecture

at least Linux, Windows

Additional Information

No response