WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: troubleshooting compilation of gfortran  (Read 3503 times)

Offline xenodius

  • Newbie
  • *
  • Posts: 43
troubleshooting compilation of gfortran
« on: December 21, 2020, 09:32:17 PM »
Hello, I see gcc.tcz contains gfortran however, when trying to compile scipy it is not recognized. So, I set out to compile just gfortran with gcc... I haven't compiled anything on linux before.

My first try, I ran out of memory. So I tried compiling on the 2nd partition (mmcblk0p2, ~60gb) which appeared to configure; 
Code: [Select]
sudo git clone https://gcc.gnu.org/git/gcc.git
sudo ./contrib/download_prerequisites
sudo tar -xvf gmp-6.1.0.tar.bz2
sudo tar -xvf mpc-1.0.3.tar.gz
sudo tar -xvf mpfr-3.1.4.tar.bz2
sudo /mnt/mmcblk0p2/build/gcc/configure --prefix=/mnt/mmcblk0p2/build/gcc --enable-languages=c,fortran
sudo make -j4 DESTDIR=/mnt/mmcblk0p2/build/gcc-build

however, make eventually returned:
Code: [Select]
checking how to run the C preprocessor... /lib/cpp
configure: error: in `/mnt/mmcblk0p2/build/gcc-build/armv7l-unknown-linux-gnueabihf/libgcc':
configure: error: C preprocessor "/lib/cpp" fails sanity check
See `config.log' for more details
make[2]: *** [Makefile:20136: configure-stage1-target-libgcc] Error 1
make[2]: Leaving directory '/mnt/mmcblk0p2/build/gcc-build'
make[1]: *** [Makefile:25512: stage1-bubble] Error 2
make[1]: Leaving directory '/mnt/mmcblk0p2/build/gcc-build'
make: *** [Makefile:1001: all] Error 2

Seems like I'm missing something needed to compile C, or a path to it? I have gcc, gmp, mpfr, and mpc tcz's... however, gcc would not configure without the source for gmp, mpfr, and mpc, detecting gmp but not mpfr/mpc the first try, so I grabbed them all via './contrib/download_prerequisites' as above before I ran out of memory and tried it on mmcblk0p2.

I've attached the config.log, which included some surprisingly kinky commentary that may be irrelevant but I feel compelled to draw attention to below. Easter egg?
Code: [Select]
conftest.c:17:5: error: unknown type name 'choke'
   17 |     choke me
      |     ^~~~~
........
| {
|     #if MPFR_VERSION < MPFR_VERSION_NUM(3,1,6)
|     choke me
|     #endif
|   ;
|   return 0;
| }
configure:7812: result: buggy but acceptable



Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10363
Re: troubleshooting compilation of gfortran
« Reply #1 on: December 21, 2020, 09:44:07 PM »
Hi xenodius
... I have gcc, gmp, mpfr, and mpc tcz's... however, gcc would not configure without the source for gmp, mpfr, and mpc, ...
You might need the  dev  files (gmp-dev.tcz, mpfr-dev.tcz, and mpc-dev.tcz), not the source packages.

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7179
    • My Community Forum
Re: troubleshooting compilation of gfortran
« Reply #2 on: December 21, 2020, 09:49:02 PM »
When you are reporting a bug, please report OS release version and the version, packing date of extension.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 13997
Re: troubleshooting compilation of gfortran
« Reply #3 on: December 21, 2020, 09:54:01 PM »
To compile gcc you need something like:
Code: [Select]
$ tce-load compiletc mpc-dev python3.8

Offline snecker

  • Newbie
  • *
  • Posts: 11
Re: troubleshooting compilation of gfortran
« Reply #4 on: December 22, 2020, 01:24:43 AM »
Hello, I see gcc.tcz contains gfortran however, when trying to compile scipy it is not recognized. So, I set out to compile just gfortran with gcc... I haven't compiled anything on linux before.

My first try, I ran out of memory. So I tried compiling on the 2nd partition (mmcblk0p2, ~60gb) which appeared to configure; 
Code: [Select]
sudo git clone https://gcc.gnu.org/git/gcc.git
sudo ./contrib/download_prerequisites
sudo tar -xvf gmp-6.1.0.tar.bz2
sudo tar -xvf mpc-1.0.3.tar.gz
sudo tar -xvf mpfr-3.1.4.tar.bz2
sudo /mnt/mmcblk0p2/build/gcc/configure --prefix=/mnt/mmcblk0p2/build/gcc --enable-languages=c,fortran
sudo make -j4 DESTDIR=/mnt/mmcblk0p2/build/gcc-build

I would add that you shouldn't do any of this as root. You are also downloading a git checkout which will likely be the development branch and possibly broken, therefore try with the current stable 10.2 release:

https://gcc.gnu.org/mirrors.html

e.g.

ftp://ftp.mirrorservice.org/sites/sourceware.org/pub/gcc/releases/gcc-10.2.0/gcc-10.2.0.tar.gz

Offline xenodius

  • Newbie
  • *
  • Posts: 43
Re: troubleshooting compilation of gfortran
« Reply #5 on: December 22, 2020, 04:37:19 PM »
I would add that you shouldn't do any of this as root.
I had to use root I think because of my permissions on /mnt/... worked without it in /tmp/, just ran out of space that way. I tried the 10.2 branch this morning, was excited when it ran fine for >15 minutes... but I just got back 11 hours later and it appears to be looping the exact same lines every 7-8 seconds... Pi is still working based on temp. I expected a few hours, but now wondering if it might go forever. :o

To bmarkus, Juanito, and Rich,
I should have been clearer on those details, sorry-- I think I have all that loaded. Relevant onboot packages:
Code: [Select]
piCore 11.0beta2, kernel 4.19.81-v7L on Pi4B
gcc, gcc_base-dev, gcc_libs, gcc_libs-dev: 9.2.0
compiletc 9.0
mpc, mpc-dev 1.1.0
mpfr, mpfr-dev 3.1.4
make 4.2.1
cmake 3.15.5
autoconf 2.69
automake 1.16.2
python3.8
« Last Edit: December 22, 2020, 04:46:32 PM by xenodius »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10363
Re: troubleshooting compilation of gfortran
« Reply #6 on: December 22, 2020, 05:10:11 PM »
Hi xenodius
Looking at this:
http://tinycorelinux.net/6.x/armv6/tcz/gcc.tcz.list
I see this:
Code: [Select]
usr/local/bin/cpp
usr/local/bin/armv6l-unknown-linux-gnueabihf-gfortran
usr/local/bin/armv6l-unknown-linux-gnueabihf-gcc-ar
usr/local/bin/gcc
usr/local/bin/gcc-nm
usr/local/bin/armv6l-unknown-linux-gnueabihf-gcc-4.9.2
usr/local/bin/armv6l-unknown-linux-gnueabihf-gcc-ranlib
usr/local/bin/armv6l-unknown-linux-gnueabihf-g++
usr/local/bin/armv6l-unknown-linux-gnueabihf-gcc-nm
usr/local/bin/armv6l-unknown-linux-gnueabihf-gcc
usr/local/bin/gcc-ar
usr/local/bin/gcc-ranlib
usr/local/bin/c++
usr/local/bin/armv6l-unknown-linux-gnueabihf-c++
usr/local/bin/g++
For every long version of a command there is a short version, except except  gfortran.

Hello, I see gcc.tcz contains gfortran however, when trying to compile scipy it is not recognized. ...
If you do this:
Code: [Select]
sudo cp -a /tmp/tcloop/gcc/usr/local/bin/armv6l-unknown-linux-gnueabihf-gfortran /usr/local/bin/gfortranDoes it work then?

Offline xenodius

  • Newbie
  • *
  • Posts: 43
Re: troubleshooting compilation of gfortran
« Reply #7 on: December 25, 2020, 01:09:54 PM »
Hey Rich, a short version sounds great but I'd be happy with anything that works. Once I setup all these dependencies and backup the image I should be good more or less indefinitely. I tried copying just one and both of:
Code: [Select]
usr/local/bin/armv7l-unknown-linux-gnueabihf-gfortran
usr/local/bin/gfortran
to /usr/loca/bin/gfortran, from 7.x armv7 repo (I am on 11x but 7x was the latest repo I found containing these fortran files). To compile scipy I need BLAS then LAPACK, which themselves need GFortran, each time I tried to compile OpenBLAS-0.3.13 I got:
Code: [Select]
gfortran: error trying to exec 'f951': execvp: No such file or directory
gfortran: error trying to exec 'make[2]: *** [<builtin>: sgbbrd.o] Error 1
make[2]: *** Waiting for unfinished jobs....
f951': execvp: No such file or directory
make[2]: *** [<builtin>: spotrf2.o] Error 1
gfortrangfortran: error trying to exec 'f951': execvp: No such file or directory
: error trying to exec 'f951': execvp: No such file or directory
make[2]: *** [<builtin>: sgetrf2.o] Error 1
make[2]: *** [<builtin>: sgbcon.o] Error 1
make[2]: Leaving directory '/mnt/mmcblk0p2/build/blas/OpenBLAS-0.3.13/lapack-netlib/SRC'
make[1]: *** [Makefile:27: lapacklib] Error 2
make[1]: Leaving directory '/mnt/mmcblk0p2/build/blas/OpenBLAS-0.3.13/lapack-netlib'
make: *** [Makefile:244: netlib] Error 2

Googling found some cases on MAC OSx with this error, that was fixed by linking f951 in the PATH to the binary of gfortran or reinstalling gcc/gfortran, but I have not been able to find out how to do this in piCore. Googling about linux generally I see that there are lots of types of links (hard, soft, symbolic?) and I'm not sure which is needed here. This is new territory for me but I didn't expect this much trouble since gcc has already been compiled for every version of piCore.
« Last Edit: December 25, 2020, 01:14:00 PM by xenodius »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10363
Re: troubleshooting compilation of gfortran
« Reply #8 on: December 25, 2020, 01:22:31 PM »
Hi xenodius
... to /usr/loca/bin/gfortran, from 7.x armv7 repo (I am on 11x but 7x was the latest repo I found containing these fortran files). ...
You can't copy binaries from one version of gcc to another.

When you said:
Hello, I see gcc.tcz contains gfortran however, when trying to compile scipy it is not recognized. ...
I thought you meant it contained something like:
Code: [Select]
usr/local/bin/armv6l-unknown-linux-gnueabihf-gfortranbut was missing:
Code: [Select]
usr/local/bin/gfortranwhich is just a renamed copy (or maybe a hardlink).

Offline xenodius

  • Newbie
  • *
  • Posts: 43
Re: troubleshooting compilation of gfortran
« Reply #9 on: December 25, 2020, 06:50:27 PM »
Here I was thinking the longshot was 11x vs. 7x piCore, but it makes sense that'd be a sure break.

I suggested gcc.tcz contains gfortran because with the 11x gcc.tcz,
Code: [Select]
gcc -v returns the configuration,
Code: [Select]
./gcc-9.2.0/configure --libdir=/usr/lib --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-c99 --enable-long-long --enable-clocale=gnu --enable-languages=c,c++,fortran,go --disable-multilib --disable-libstdcxx-pch --enable-cloog-backend=isl --with-isl=/usr --with-system-zlib --enable-frame-pointer --disable-bootstrap --enable-lto --with-pkgversion=piCore --with-arch=armv6zk --with-tune=arm1176jzf-s --with-fpu=vfp --with-float=hard --with-gxx-include-dir=/usr/include/c++/9.2.0
indicating it was compiled for c, c++, fortran, and go. I'm not sure why I can't compile source that requires fortran, but the only file with 'fortran' in the name of the gcc lib is an include:
Code: [Select]
usr/lib/gcc/armv7l-unknown-linux-gnueabihf/9.2.0/include/ISO_Fortran_binding.h
In the meantime I will see if maybe environmental variables or some configure flags will allow me to build fortran.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 13997
Re: troubleshooting compilation of gfortran
« Reply #10 on: December 26, 2020, 12:09:37 AM »
The x86 build notes are here: http://tinycorelinux.net/10.x/x86/tcz/src/gfortran

..and you could take a look at:

http://tinycorelinux.net/10.x/x86/tcz/gfortran.tcz.info
http://tinycorelinux.net/10.x/x86/tcz/gfortran-lib.tcz.info

On piCore, you would need something like:
Code: [Select]
CC="gcc -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -Os -pipe" CXX="g++ -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -Os -pipe" ../configure --prefix=/usr/local --enable-languages=c,c++,fortran --disable-multilib --disable-bootstrap --with-system-zlib --libexecdir=/usr/local/lib

Offline xenodius

  • Newbie
  • *
  • Posts: 43
Re: troubleshooting compilation of gfortran
« Reply #11 on: December 27, 2020, 09:10:33 AM »
Juanito, those compile notes are a gem, thank you for pointing them out!
Is the purpose of these lines:
Code: [Select]
find . -name Makefile -type f -exec sed -i 's/-g -O2//g' {} \;
find . -name Makefile -type f -exec sed -i 's/-O2 -g//g' {} \;
find . -name config.status -type f -exec sed -i 's/-g -O2//g' {} \;
to replace the flags on the below variables? Just curious why this is necessary.

At any rate, no matter what I did, 'make' just looped back through the ./configure output:
Code: [Select]
tc@box:/mnt/mmcblk0p2/build/gcc/gcc-10.2.0$ sudo make -j4
make: Warning: File 'Makefile.in' has modification time 1595482727 s in the future
CONFIG_SHELL="/bin/bash" /bin/bash ./config.status --recheck
running CONFIG_SHELL=/bin/bash /bin/bash ./configure --prefix=/usr/local --disable-multilib --disable-bootstrap --with-system-zlib --libexecdir=/usr/local/lib --enable-languages=c,c++,fortran,lto --no-create --no-recursion
checking build system type... armv7l-unknown-linux-gnueabihf
checking host system type... armv7l-unknown-linux-gnueabihf
checking target system type... armv7l-unknown-linux-gnueabihf
..........................
configure: creating ./config.status
CONFIG_FILES=Makefile CONFIG_HEADERS= /bin/bash ./config.status
config.status: creating Makefile
make: Warning: File 'Makefile.in' has modification time 1595482719 s in the future
CONFIG_SHELL="/bin/bash" /bin/bash ./config.status --recheck
running CONFIG_SHELL=/bin/bash /bin/bash ./configure --prefix=/usr/local --disable-multilib --disable-bootstrap --with-system-zlib --libexecdir=/usr/local/lib --enable-languages=c,c++,fortran,lto --no-create --no-recursion
checking build system type... armv7l-unknown-linux-gnueabihf
checking host system type... armv7l-unknown-linux-gnueabihf
checking target system type... armv7l-unknown-linux-gnueabihf
............................
configure: creating ./config.status
CONFIG_FILES=Makefile CONFIG_HEADERS= /bin/bash ./config.status
config.status: creating Makefile

I eventually realized that the reason for this loop, was that the timestamps were too old. Everything was ~1970. Somehow 'make' realized that this was older than the current time, yet simultaneously all created files still had this old timestamp. So it'd create a configuration, see it's 50 years old and decide to recreate it, see the new file is 50 years old, repeat... After setting the time with 'date', and starting over with re-extracted source it appears to be working. I knew it was some silly detail! Thank you all for your suggestions-- they are greatly appreciated, I have learned something from each of your posts here and elsewhere. I will try to configure my RTC so that the time persists accurately.

This is sort of offtopic, but about NTC updating-- It seems it takes the pi >60 seconds to connect to my wifi, so my time is never updated on boot. Is there a way to postpone the NTC time update timeout beyond 60 seconds?
« Last Edit: December 27, 2020, 09:12:17 AM by xenodius »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10363
Re: troubleshooting compilation of gfortran
« Reply #12 on: December 27, 2020, 09:19:40 AM »
Hi xenodius
... to replace the flags on the below variables? Just curious why this is necessary. ...
It finds and removes those 2 flags. I think those flags in the Makefile and config file might override flags you export. We typically
compile with the  -Os  flag (smaller executable).

Quote
... Somehow 'make' realized that this was older than the current time ...
Yes, make checks timestamps to determine what does or does not need to be rebuilt.
« Last Edit: December 27, 2020, 09:21:54 AM by Rich »

Offline xenodius

  • Newbie
  • *
  • Posts: 43
Re: troubleshooting compilation of gfortran
« Reply #13 on: December 27, 2020, 12:37:04 PM »
I am still getting the following error after about a half hour:
Code: [Select]
configure: error: C preprocessor "/lib/cpp" fails sanity checkSolutions to this error for other packages/distros suggested symlinking issue. The following link causes make to fail the sanity check almost immediately:
Code: [Select]
sudo ln -s /lib/cpp /usr/local/bin/cpp
In config.log, most cache variables have nothing after '=';
Code: [Select]
ac_cv_env_CPPFLAGS_set=
ac_cv_env_CPPFLAGS_value=

So in output variables:
Code: [Select]
CPPFLAGS=''
Based on other cases users have actually had to clear CPPFLAGS/CPP environmental variables in order to compile correctly... which makes sense, I think gcc should be using the corresponding cpp source downloaded via the download_prerequisites script, not the 9.2.0 version of cpp included in gcc.tcz. And as near as I can tell from the logs, it is. If I understand the configure operation and config.log correctly, it is clearing these environmental variables (='' in config.log output variables). Probably this is reason enough not to have tried the symlink, but since it did cause it to fail faster I think I might be on the right track and it's an issue with links/environmental variables. But nothing I've tried/adapted from similar errors in other packages/distributions has worked so far. Including clearing these environmental variables, directing to /usr/local/bin/cpp, and resetting piCore to a recent backup before I touched any environmental variables. :-[
« Last Edit: December 27, 2020, 12:40:26 PM by xenodius »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 10363
Re: troubleshooting compilation of gfortran
« Reply #14 on: December 27, 2020, 01:25:08 PM »
Hi xenodius
I have to ask, you're not using the values shown in the CC and CXX flags supplied in this link:
http://tinycorelinux.net/10.x/x86/tcz/src/gfortran/compile_gfortran

This build script for gcc shows CFLAGS and CXXFLAGS suitable for armv7 being exported.
http://repo.tinycorelinux.net/8.x/armv7/tcz/src/gcc/gcc630.build