2

I believe my question is similar to this post: Linux: cannot find lgfortran though gfortran is installed. However, since the suggested answer does not fix my problem, there seems no other choice other than asking it again, for a desperate Linux new comer like me.

Here is the problem. I installed GNU fortran compiler 4.8.4 and can find it in terminal

$ which gfortran-4.8 
/usr/bin/gfortran-4.8

and

$ locate gfortran
/usr/bin/gfortran-4.7
/usr/bin/gfortran-4.8
/usr/bin/x86_64-linux-gnu-gfortran-4.7 
/usr/bin/x86_64-linux-gnu-gfortran-4.8
/usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.a
/usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.so
/usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortran.spec
/usr/lib/gcc/x86_64-linux-gnu/4.7/libgfortranbegin.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.a
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.so
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.spec
/usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortranbegin.a
/usr/lib/x86_64-linux-gnu/libgfortran.so.3
/usr/lib/x86_64-linux-gnu/libgfortran.so.3.0.0
/usr/share/doc/gfortran-4.7
/usr/share/doc/gfortran-4.8
/usr/share/doc/libgfortran-4.7-dev
/usr/share/doc/libgfortran-4.8-dev
/usr/share/doc/libgfortran3
/usr/share/man/man1/gfortran-4.7.1.gz
/usr/share/man/man1/gfortran-4.8.1.gz
/usr/share/man/man1/x86_64-linux-gnu-gfortran-4.7.1.gz
/usr/share/man/man1/x86_64-linux-gnu-gfortran-4.8.1.gz
/var/cache/apt/archives/gfortran-4.7_4.7.3-12ubuntu1_amd64.deb
/var/cache/apt/archives/gfortran-4.8_4.8.4-2ubuntu1~14.04_amd64.deb
/var/cache/apt/archives/libgfortran-4.7-dev_4.7.3-12ubuntu1_amd64.deb
/var/cache/apt/archives/libgfortran-4.8-dev_4.8.4-2ubuntu1~14.04_amd64.deb
/var/cache/apt/archives/libgfortran3_4.8.4-2ubuntu1~14.04_amd64.deb
/var/lib/dpkg/info/gfortran-4.7.list
/var/lib/dpkg/info/gfortran-4.7.md5sums
/var/lib/dpkg/info/gfortran-4.8.list
/var/lib/dpkg/info/gfortran-4.8.md5sums
/var/lib/dpkg/info/libgfortran-4.7-dev:amd64.list
/var/lib/dpkg/info/libgfortran-4.7-dev:amd64.md5sums
/var/lib/dpkg/info/libgfortran-4.8-dev:amd64.list
/var/lib/dpkg/info/libgfortran-4.8-dev:amd64.md5sums
/var/lib/dpkg/info/libgfortran3:amd64.list
/var/lib/dpkg/info/libgfortran3:amd64.md5sums
/var/lib/dpkg/info/libgfortran3:amd64.postinst
/var/lib/dpkg/info/libgfortran3:amd64.postrm
/var/lib/dpkg/info/libgfortran3:amd64.shlibs
/var/lib/dpkg/info/libgfortran3:amd64.symbols

So gfortran seems installed, although I don't understand why 4.7 version is still there after my removing it.

In setting Global Compiler Settings of Code:Blocks, when I choose GNU Fortran Compiler, and its Toolchain Executables, I tried the installation directory as

/usr 

/usr/bin 

and

/usr/lib/gcc/x86_64-linux-gnu/4.8/

as suggested in the previous post, Code:Blocks tell me

could not auto-detect installation path of "GNU Fortran Compiler".....

More details of compiler configuration is here in the image (Thanks to Mike's suggestion).

Details of tool chain executables

And here's the full list of compilers on my computer:

List of Compliers

Community
  • 1
  • 1
Woodpecker Wang
  • 49
  • 3
  • 10
  • Welcome to SO! When you claim that your post is no duplicate, please show how existing posts fail solving your issue – Mario Trucco Oct 20 '15 at 21:09
  • @MarioTrucco As I said, I've tried the C:B installation directory as `/usr/lib/gcc/x86_64-linux-gnu/4.8/` and it didn't work. – Woodpecker Wang Oct 20 '15 at 23:47
  • Please add this information: the exact name of the compiler shown in **GNU Fortran Compiler** -> **Toolchain executables** -> **Program Files** -> **C Compiler** – Mike Kinghan Oct 21 '15 at 07:12
  • 1
    I'm guessing this is because your compiler is named `gfortran-4.8` and not just `gfortran`. See if there is an option somewhere in your IDE to specify the name of the compiler executable, not just its installation path. – casey Oct 21 '15 at 14:11
  • Thanks @casey. Adding -4.8 solves the problem. – Woodpecker Wang Oct 21 '15 at 14:58

3 Answers3

1

Your posting shows that you have both gfortran-4.7 and gfortran-4.8 installed under /usr/bin.

Having multiple GCC Fortran compilers (or multiple C or C++ compilers) is perfectly valid and commonplace. Code::Blocks will allow you configure as many Fortran compilers as you have got, provided you give them different names. It's also fine if you just want to configure one of them as the "GNU Fortran Compiler" and ignore the others.

But in any case, Code::Blocks must be able to unambiguously identify the installed compiler that you are calling "GNU Fortran Compiler". You have specified the Compiler's installation directory as /usr/bin and have left the Program files compiler name as gfortran.

There is no such compiler as /usr/bin/gfortran in your system, and there is no program called gfortran anywhere in your PATH. You have /usr/bin/gfortran-4.7 and /usr/bin/gfortran-4.8. As you have installed both of them, Code::Blocks assumes you want both of them. It can't tell which one of them you want to configure as "GNU Fortran Compiler".

So:-

  • Set Compiler's installation directory = /usr/bin
  • In Program files, change all occurrences of gfortran to gfortran-4.8, if you want "GNU Fortran Compiler" to mean gfortran-4.8.
  • OK out.
Mike Kinghan
  • 55,740
  • 12
  • 153
  • 182
  • Thanks Mike for such a step by step instruction. Now I see the version number matters. And the Helloworld now is compiled. Thanks you a lot! – Woodpecker Wang Oct 21 '15 at 14:55
  • You're welcome. If you want 4.7 as well as 4.8 configured in C::B, go to **Global compiler settings** -> **GNU Fortran Compiler** -> **Copy**. Click **Copy**, pick a nickname for 4.7 and then make the obvious 4.8 -> 4.7 changes in the new compiler's configuration. – Mike Kinghan Oct 21 '15 at 15:07
0

Default compiler name in 20.3 version was mingw32-gfortran. However, the executable name coming with installation is x86_64-w64-mingw32-gfortran. If this is written in compiler settings. It works.enter image description here

0

The install file codeblocks-20.03mingw-setup installs the file gfortran.exe into the C:\Program Files\CodeBlocks\MinGW\bin directory. However the Settings>Compiler>toolchainexecutables autodetect function looks for mingw32-gfortran.exe.

To fix this, in toolchainexecutables, change the filename mingw32-gfortran.exe to gfortran.exe in 3 places, then autodetect will find it.

James Risner
  • 5,451
  • 11
  • 25
  • 47