# Cannot compile CMake from source: Fortran compiler not found

**URL:** https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349
**Category:** Development
**Tags:** os:linux
**Created:** [November 2, 2023, 7:40pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349 "2023-11-02T19:40:17Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 2, 2023, 7:40pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/1 "2023-11-02T19:40:17Z")

</div>

Hello, I’m trying to compile CMake from source but I’m running into issues.  
The first command I run is:

```sh
./bootstrap CC=cc CXX=c++ --generator="Unix Makefiles" --no-debugger CFLAGS="-fno-sanitize=undefined -fno-sanitize-trap=undefined" CXXFLAGS="-fno-sanitize=undefined -fno-sanitize-trap=undefined" LDFLAGS="-s"

```

This successfully builds the “initial CMake” which is then automatically run. Somewhere along the build I get this error about missing OpenSSL:

```plaintext
-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) 
CMake Error at Utilities/cmcurl/CMakeLists.txt:587 (message):
  Could not find OpenSSL. Install an OpenSSL development package or
  configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.

```

There’s no way to pass `-DCMAKE_USE_OPENSSL=OFF` to the bootstrap script, so I manually invoke the “initial CMake” with the aforementioned flag:

```sh
./Bootstrap.cmk/cmake -DCMAKE_USE_OPENSSL=OFF .

```

The build continues then I get another error:

```plaintext
-- Looking for a Fortran compiler - NOTFOUND

```

That’s strange. I review the [readme](https://github.com/Kitware/CMake/blob/master/README.rst) but there’s no mention of a Fortran compiler, only a C++ one… Is that an error in the documentation or did I do something wrong?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [November 2, 2023, 8:05pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/2 "2023-11-02T20:05:12Z")

</div>

The check for a Fortran compiler is only for the test suite. Not finding it is not an error.

> [@johndoesstuff](#):
>
> There’s no way to pass `-DCMAKE_USE_OPENSSL=OFF` to the bootstrap script

```console
$ ./bootstrap ... -- -DCMAKE_USE_OPENSSL=OFF

```

---

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 2, 2023, 8:17pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/3 "2023-11-02T20:17:11Z")

</div>

> `$ ./bootstrap ... -- -DCMAKE_USE_OPENSSL=OFF`

Many thanks!

> [@brad.king](#):
>
> The check for a Fortran compiler is only for the test suite. Not finding it is not an error.

It completely stops the build process though:

```plaintext
-- Looking for a Fortran compiler - NOTFOUND
-- Configuring incomplete, errors occurred!
---------------------------------------------
Error when bootstrapping CMake:
Problem while running initial CMake
---------------------------------------------

```

Any way to bypass this?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 2, 2023, 9:10pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/4 "2023-11-02T21:10:59Z")

</div>

> [@johndoesstuff](#):
>
> ```auto
> -- Configuring incomplete, errors occurred!
> ---------------------------------------------
> Error when bootstrapping CMake:
> Problem while running initial CMake
> ---------------------------------------------
> 
> ```

The error could have been before that last line. Can you please provide the full log?

---

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 2, 2023, 11:39pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/5 "2023-11-02T23:39:12Z")

</div>

> [@ben.boeckel](#):
>
> Can you please provide the full log?

Sure thing.

> **[cmake.log - Pastebin.com](https://pastebin.com/YBSaK6j0)**
>
> Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 3, 2023, 2:04am UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/6 "2023-11-03T02:04:31Z")

</div>

The actual errors seem to be `try_compile` related:

```auto
-- Check size of sa_family_t
CMake Error at Modules/CheckTypeSize.cmake:146 (try_compile):
  Cannot copy output executable
 
    ''
 
  to destination specified by COPY_FILE:
 
    '/tmp/cmake-3.27.7/CMakeFiles/CheckTypeSize/SIZEOF_SA_FAMILY_T.bin'
 
  because:
 
    No such file or directory (input)
 
  Recorded try_compile output location doesn't exist:
 
    /tmp/cmake-3.27.7/CMakeFiles/CMakeScratch/TryCompile-BmCOMg/cmTC_b7220
 
Call Stack (most recent call first):
  Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
  Utilities/cmcurl/CMakeLists.txt:1289 (check_type_size)

```

I see some sanitizer flags in the bootstrap output; does it work if you don’t use a sanitizer?

---

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 3, 2023, 9:25am UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/7 "2023-11-03T09:25:10Z")

</div>

> [@ben.boeckel](#):
>
> I see some sanitizer flags in the bootstrap output; does it work if you don’t use a sanitizer?

Do you mean `-fno-sanitize=undefined -fno-sanitize-trap=undefined` ? These flags do turn off UBsan, which is on by default and prevents even the initial CMake from being built… I only added them to the bootstrap command though, maybe they’re not getting passed to the initial CMake?

Is it possible to see the full compiler error message that occurs during `try_compile`?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 3, 2023, 12:01pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/8 "2023-11-03T12:01:40Z")

</div>

`CMakeFiles/*.yaml` has info (I can’t remember the name…`CMakeConfigure.yaml`?), but `--debug-trycompile` passed to the configure will leave the `try_compile` trees around for investigation.

---

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 3, 2023, 1:25pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/9 "2023-11-03T13:25:47Z")

</div>

> [@ben.boeckel](#):
>
> `CMakeFiles/*.yaml` has info

I couldn’t find any .yaml files in the source tree at all, but I did find 3 log files containing errors…

- [Bootstrap.cmk/cmake\_bootstrap.log](https://pastebin.com/jdnsV6Zu): errors in Source/Checks and Source/kwsys.
- [CMakeFiles/CMakeError.log](https://pastebin.com/Asd8UPBy): errors about missing Curses and a Fortran compiler.
- CMakeFiles/CMakeOutput.log: errors in CurlTests.c  
`https://pastebin.com/pLrZFVJs`

(I can only post 2 links per comment)

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 3, 2023, 3:38pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/10 "2023-11-03T15:38:57Z")

</div>

`./bootstrap … -- --debug-trycompile` may have more information stick around.

---

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 3, 2023, 4:04pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/11 "2023-11-03T16:04:31Z")

</div>

> `./bootstrap … -- --debug-trycompile`

That’s what I did… I tried again now, same thing, no yaml files.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [November 3, 2023, 4:42pm UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/12 "2023-11-03T16:42:45Z")

</div>

Hrm. Well, the paths in the error messages should be around at least. Can you go in those, try and build them and see what might be wrong there?

---

<div class="post-metadata">

### Author: ![johndoesstuff](https://discourse.cmake.org/user_avatar/discourse.cmake.org/johndoesstuff/32/3978_2.png) [@johndoesstuff](https://discourse.cmake.org/u/johndoesstuff)
#### Post date: [November 8, 2023, 2:05am UTC](https://discourse.cmake.org/t/cannot-compile-cmake-from-source-fortran-compiler-not-found/9349/13 "2023-11-08T02:05:42Z")

</div>

It turned out to be a linker issue; `cc` was symlinked to `ld` so it wasn’t working properly. Once that was fixed CMake built without issues (at least I hope so!)

Thank you so much Ben and Brad for the help 😄
