Menu

#193 Problem creating standalone programs with gfortran under MSYS2

1.0
closed
nobody
None
2017-02-04
2015-09-07
No

As I reported on comp.lang.fortran (https://groups.google.com/forum/?hl=nl#!topic/comp.lang.fortran/RKqtI2EHNU) I have a problem creating a standalone executable program using gfortran. I use a command-line like:
gfortran -o myprogram myprogram.f90 -stat-libgfortran -Bstatic
to force gfortran to use all static libraries. However, this results in unresolved externals:
/usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(write.o):(.text$write_float+0x15c): relocation truncated to fit: R_X86_64_PC32 against undefined symbol quadmath_snprintf' /usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(write.o):(.text$write_float+0x7cf): relocation truncated to fit: R_X86_64_PC32 against undefined symbolquadmath_snprintf'
/usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(write.o):(.text$write_float+0x84e): relocation truncated to fit: R_X86_64_PC32 against undefined symbol quadmath_snprintf' /usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(write.o):(.text$write_float+0xf22): relocation truncated to fit: R_X86_64_PC32 against undefined symbolquadmath_snprintf'
/usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(write.o):(.text$write_float+0x1781): relocation truncated to fit: R_X86_64_PC32 against undefined symbol quadmath_snprintf' /usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(read.o):(.text$_gfortrani_convert_real+0x72): relocation truncated to fit: R_X86_64_PC32 against undefined symbolstrtoflt128'
/usr/lib/gcc/x86_64-pc-msys/4.9.2/libgfortran.a(read.o):(.text$_gfortrani_convert_infnan+0x53): relocation truncated to fit: R_X86_64_PC32 against undefined symbol `strtoflt128'
collect2: error: ld returned 1 exit status

Adding libquadmath.a explicitly doesn't help.

One of the developers of gfortran informed in the discussion on comp.lang.fortran that the triplet x86_64-pc-msys was new to him.

How do I solved this problem?

Discussion

  • Ray Donnelly

    Ray Donnelly - 2015-09-07

    Here you are using msys2 GCC which links to msys-2.0.dll. We don't provide gfortran for msys2 GCC, only for the mingw-w64 GCC compilers that we provide. msys2 tools are not the focus of the MSYS2 software distribution, only a means to an end, that end being native Windows software.

    You should install mingw-w64-{i686,x86_64}-toolchain with pacman, and launch your shell using mingw{32,64}_shell.bat instead.

     
    • Angelo Graziosi

      Angelo Graziosi - 2015-09-07

      Hmm.. You DO provide gfortran for MSYS2,

      $ pacman -Ss fortran
      [...]
      msys/gcc-fortran 4.9.2-5 (msys2-devel) [installato]
          Fortran front-end for GCC
      

      Regarding the options to build sattically, to have a fully native Windows applications I use only "-static", as in

      $ gfortran -Wall -O3 -static testshape.f90 -o testshape64
      

      (froma MINGW32/64 shell). In this way I can start "testshape64.exe" from Windows Start/Run menu. If I use

      $ gfortran -Wall -O3 testshape.f90 -o testshape64 -static-libgfortran -Bstatic
      

      "testshape64.exe" is 10 times shorter in size and DOES NOT run from Windows Start/Run menu. It complains for missing DLL (for example libwinpthread...).

      Obviously in more complex cases, I need to add extra libs. For example:

      $ gfortran -O3 -Wall -static bgi.f90 mandelbrot.f90 -L ~/programming/lib/mingw64 -lWinBGIm6.0 -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32 -lstdc++ -o mandelbrot-mingw64
      

      being WinBGIm6.0 a C++ library, or

      $  gfortran -O3 -Wall -static -mwindows win32_interface.f90 planar3body.f90 planar3body.res -o planar3body64
      

      Ciao,
      Angelo.

       
      • Arjen Markus

        Arjen Markus - 2015-09-08

        The output of "pacman -Ss fortran" is:

        mingw32/mingw-w64-i686-cfitsio 3.370-1
        A library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format (mingw-w64)
        mingw32/mingw-w64-i686-gcc-fortran 4.9.2-5 (mingw-w64-i686-toolchain mingw-w64-i686)
        GNU Compiler Collection (Fortran) for MinGW-w64
        mingw32/mingw-w64-i686-gcc-fortran-debug 4.9.1-3
        Detached debugging symbols for mingw-w64-i686-gcc-fortran
        mingw32/mingw-w64-i686-gcc-libgfortran 4.9.2-5 (mingw-w64-i686-toolchain mingw-w64-i686)
        GNU Compiler Collection (libgfortran) for MinGW-w64
        mingw32/mingw-w64-i686-gcc-libgfortran-debug 4.9.1-3
        Detached debugging symbols for mingw-w64-i686-gcc-libgfortran
        mingw32/mingw-w64-i686-qrupdate-svn r28-2 (mingw-w64-i686)
        qrupdate is a Fortran library for fast updates of QR and Cholesky decompositions.
        mingw64/mingw-w64-x86_64-cfitsio 3.370-1
        A library of C and Fortran subroutines for reading and writing data files in FITS (Flexible Image Transport System) data format (mingw-w64)
        mingw64/mingw-w64-x86_64-gcc-fortran 4.9.2-5 (mingw-w64-x86_64-toolchain mingw-w64-x86_64)
        GNU Compiler Collection (Fortran) for MinGW-w64
        mingw64/mingw-w64-x86_64-gcc-fortran-debug 4.9.1-3
        Detached debugging symbols for mingw-w64-x86_64-gcc-fortran
        mingw64/mingw-w64-x86_64-gcc-libgfortran 4.9.2-5 (mingw-w64-x86_64-toolchain mingw-w64-x86_64)
        GNU Compiler Collection (libgfortran) for MinGW-w64
        mingw64/mingw-w64-x86_64-gcc-libgfortran-debug 4.9.1-3
        Detached debugging symbols for mingw-w64-x86_64-gcc-libgfortran
        mingw64/mingw-w64-x86_64-qrupdate-svn r28-2 (mingw-w64-x86_64)
        qrupdate is a Fortran library for fast updates of QR and Cholesky decompositions.
        msys/gcc-fortran 4.9.2-4 (msys2-devel) [installed]
        Fortran front-end for GCC

        So it seems the right toolchain has been installed. I run the mingw64_shell.bat, but "gfortran -v" says the target is x86_64-pc-msys

        (I cannot install/sync the mingw-w64-x86_64-toolchain, as suggested by Ray, as the SFdownload site is down at the moment)

         
        • Ray Donnelly

          Ray Donnelly - 2015-09-08

          Why do you think the right toolchain has been installed? As mentioned on comp.lang.fortran, the triplet x86_64-pc-msys is unknown to them. The only gcc-fortran package you've installed is:

          msys/gcc-fortran 4.9.2-4 (msys2-devel) [installed]

          .. the important information from here is "msys" and "[installed]".

          As I said already you need to install the mingw-w64-x86_64-toolchain package group, specifically from it mingw-w64-x86_64-gcc-fortran.

          Regarding your sourceforge connectivity issues, we changed our primary mirrors to a donated server about a month ago. You should have this change already unless you haven't updated your system for longer than that.

          You could hand edit three files in /etc/pacman.d adding the following above the sourceforge entries:

          mirrorlist.mingw32:
          ## Primary
          ## msys2.org
          Server = http://repo.msys2.org/mingw/i686
          
          mirrorlist.mingw64:
          ## Primary
          ## msys2.org
          Server = http://repo.msys2.org/mingw/x86_64
          
          mirrorlist.msys:
          ## Primary
          ## msys2.org
          Server = http://repo.msys2.org/msys/$arch
          

          Largely speaking, mingw-w64 executables live in /mingw32/bin (for i686) and /mingw64/bin (for x86_64) and all msys2 executables live in /usr/bin. When you need to determine which package an executable you need might come from you can use pkgfile and guess at it as follows:

          pacman -S pkgfile
          pkgfile --update
          pkgfile /mingw64/bin/gfortran.exe
          

          Good luck.

           

          Last edit: Ray Donnelly 2015-09-08
          • Arjen Markus

            Arjen Markus - 2015-09-08

            I got that impression from lines like:

            mingw64/mingw-w64-x86_64-gcc-fortran 4.9.2-5 (mingw-w64-x86_64-toolchain mingw-w64-x86_64)
            GNU Compiler Collection (Fortran) for MinGW-w64/

            Anyway, I updated the pacman.d files as per your receipe, but unfortunately that server is also unreachable:

            warning: failed to retrieve some files
            error: failed retrieving file 'mingw-w64-x86_64-winstorecompat-git-5.0.0.449754261-1-any.pkg.tar.xz' from repo.msys2.org : The requested URL returned erro404
            error: failed retrieving file 'mingw-w64-x86_64-winstorecompat-git-5.0.0.449754261-1-any.pkg.tar.xz' from downloads.sourceforge.net : The requested URL rened error: 404
            warning: failed to retrieve some files
            error: failed to commit transaction (unexpected error)
            Errors occurred, no packages were upgraded.

            Thanks for your patience sofar, though

             
  • Arjen Markus

    Arjen Markus - 2015-09-07

    Ah, the shell I started was mingw_64_shell.bat, but the toolchain you mention is indeed not installed.

    Thanks

     
  • Ray Donnelly

    Ray Donnelly - 2015-09-08

    pacman -Ss doesn't list installed packages, it searches for all available ones matching the string and in the results, [installed] indicates, well, you know what it indicates.

    I've no idea why you can't reach repo.msys2.org, do you have some firewall issues? I can reach sf and repo.msys2.org.

     

    Last edit: Ray Donnelly 2015-09-08
  • Ray Donnelly

    Ray Donnelly - 2015-09-08

    That package no longer exists because it's been replaced by a newer one. Please update your package database with pacman -Sy or update your database and update to newer versions of your installed packages all in one line with pacman -Syu, then try to install your packages.

    Perhaps you could read our wiki on this site? These things are all explained in some detail there, including a safer update procedure than just pacman -Syu

     

    Last edit: Ray Donnelly 2015-09-08
  • Arjen Markus

    Arjen Markus - 2015-09-08

    Well, that certainly did the trick - there was indeed something blocking my access. When I turned it off, I got through, did the update and did the installation of the toolchain. It works now. Thanks again.

     
  • David Macek

    David Macek - 2017-02-04
    • status: open --> closed
     
  • David Macek

    David Macek - 2017-02-04

    Closing as resolved.

     
MongoDB Logo MongoDB