# \_common\_patterns FAIL\_REGEX error on running cmake

**URL:** https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671
**Category:** Usage
**Created:** [October 2, 2024, 5:48pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671 "2024-10-02T17:48:31Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![obioradiegwu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/22d042/32.png) [@obioradiegwu](https://discourse.cmake.org/u/obioradiegwu)
#### Post date: [October 2, 2024, 5:48pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/1 "2024-10-02T17:48:31Z")

</div>

I am migrating my dev boxes from RHEL8 (gcc11) to RHEL9 (gcc13) while maintaining the version of my cmake (3.21.3). Wile testing the migration, i’ve noticed the following error

```auto
/usr/share/cmake/Modules/Internal/CheckCompilerFlag.cmake(17): check_compiler_flag_common_patterns(_common_patterns )
/usr/share/cmake/Modules/CMakeCheckCompilerFlagCommonPatterns.cmake(10): set(_common_patterns FAIL_REGEX [Uu]nrecogni[sz]ed .*option FAIL_REGEX switch .* is no longer supported FAIL_REGEX unknown .*option FAIL_REGEX optimization flag .* not supported FAIL_REGEX unknown argument ignored FAIL_REGEX ignoring unknown option FAIL_REGEX warning D9002 FAIL_REGEX option.*not supported FAIL_REGEX invalid argument .*option FAIL_REGEX ignoring option .*argument required FAIL_REGEX ignoring option .*argument is of wrong type FAIL_REGEX [Uu]nknown option FAIL_REGEX [Ww]arning: [Oo]ption FAIL_REGEX command option .* is not recognized FAIL_REGEX command option .* contains an incorrect subargument FAIL_REGEX Option .* is not recognized. Option will be ignored. FAIL_REGEX not supported in this configuration. ignored FAIL_REGEX File with unknown suffix passed to linker FAIL_REGEX [Uu]nknown switch FAIL_REGEX WARNING: unknown flag: FAIL_REGEX Incorrect command line option: FAIL_REGEX Warning: illegal option FAIL_REGEX [Ww]arning: Invalid suboption FAIL_REGEX An invalid option .* appears on the command line FAIL_REGEX WARNING: invalid compiler option )
/usr/share/cmake/Modules/Internal/CheckCompilerFlag.cmake(18): cmake_check_source_compiles(${_lang} ${_lang_src} ${_var} ${_lang_fail_regex} ${_common_patterns} OUTPUT_VARIABLE _output )

```

This error is elicited from calling the following function

```auto
function(set_compiler_flag _result)
    # loop over all flags, try to find the first which works
    set(_list_of_flags_result)
    foreach(_arg IN ITEMS ${ARGN})
        check_cxx_compiler_flag("${_arg}" _${_arg}_works)

        # if the flag works, use it,
        if(_${_arg}_works)
            list(APPEND _list_of_flags_result "${_arg}")
        endif()
	 list(APPEND _list_of_flags_result "${_arg}")
    endforeach()

    set(${_result} "${_list_of_flags_result}" PARENT_SCOPE)
endfunction()

```

From this call site

```auto
    set_compiler_flag(GCC_FLAGS
                      "-Wall"
                      "-Wextra"
                      "-Wcast-qual"
                      "-Wconversion-null"
                      "-Wmissing-declarations"
                      "-Woverlength-strings"
                      "-Wpointer-arith"
                      "-Wunused-local-typedefs"
                      "-Wunused-result"
                      "-Wvarargs"
                      "-Wvla"
                      "-Wwrite-strings"
                      "-Wno-sign-compare"
                      "-pipe"
                      "-fconcepts"
                      "-g" # always include debug information - even for releases

                      # We disable the AVX512 instruction sets to avoid CPU frequency throttling
                      "-march=native"
                      "-mno-avx512f"
                      "-mno-avx512pf"
                      "-mno-avx512er"
                      "-mno-avx512cd"
                      )

```

Any ideas why it doesn’t work on RH9 for the same version of cmake?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 2, 2024, 6:16pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/2 "2024-10-02T18:16:02Z")

</div>

The output you’ve posted doesn’t look like an error, but a normal piece of `cmake --trace` output. If you’re getting an error, can you post that?

---

<div class="post-metadata">

### Author: ![obioradiegwu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/22d042/32.png) [@obioradiegwu](https://discourse.cmake.org/u/obioradiegwu)
#### Post date: [October 2, 2024, 6:28pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/3 "2024-10-02T18:28:57Z")

</div>

Hi @Angew,  
Thanks. All the compiler flags now fail the check\_cxx\_compiler\_flag tests as follows. What is baffling is that I can invoke the compiler (when called standalone) with these flags successfully

```auto
-- Performing Test _-fexceptions_works
-- Performing Test _-fexceptions_works - Failed
-- Performing Test _-Wall_works
-- Performing Test _-Wall_works - Failed
-- Performing Test _-Wextra_works
-- Performing Test _-Wextra_works - Failed
-- Performing Test _-Wcast-qual_works
-- Performing Test _-Wcast-qual_works - Failed
-- Performing Test _-Wconversion-null_works
-- Performing Test _-Wconversion-null_works - Failed
-- Performing Test _-Wmissing-declarations_works
-- Performing Test _-Wmissing-declarations_works - Failed
-- Performing Test _-Woverlength-strings_works
-- Performing Test _-Woverlength-strings_works - Failed
-- Performing Test _-Wpointer-arith_works
-- Performing Test _-Wpointer-arith_works - Failed
-- Performing Test _-Wunused-local-typedefs_works
-- Performing Test _-Wunused-local-typedefs_works - Failed
-- Performing Test _-Wunused-result_works
-- Performing Test _-Wunused-result_works - Failed
-- Performing Test _-Wvarargs_works
-- Performing Test _-Wvarargs_works - Failed
-- Performing Test _-Wvla_works
-- Performing Test _-Wvla_works - Failed
-- Performing Test _-Wwrite-strings_works
-- Performing Test _-Wwrite-strings_works - Failed
-- Performing Test _-Wno-sign-compare_works
-- Performing Test _-Wno-sign-compare_works - Failed
-- Performing Test _-pipe_works
-- Performing Test _-pipe_works - Failed
-- Performing Test _-fconcepts_works
-- Performing Test _-fconcepts_works - Failed
-- Performing Test _-g_works
-- Performing Test _-g_works - Failed
-- Performing Test _-march=native_works
-- Performing Test _-march=native_works - Failed
-- Performing Test _-mno-avx512f_works
-- Performing Test _-mno-avx512f_works - Failed
-- Performing Test _-mno-avx512pf_works
-- Performing Test _-mno-avx512pf_works - Failed
-- Performing Test _-mno-avx512er_works
-- Performing Test _-mno-avx512er_works - Failed
-- Performing Test _-mno-avx512cd_works
-- Performing Test _-mno-avx512cd_works - Failed
-- Performing Test _-Wno-conversion-null_works
-- Performing Test _-Wno-conversion-null_works - Failed
-- Performing Test _-Wno-missing-declarations_works
-- Performing Test _-Wno-missing-declarations_works - Failed
-- Performing Test _-Wno-unused-function_works
-- Performing Test _-Wno-unused-function_works - Failed
-- Performing Test _-Wno-unused-parameter_works
-- Performing Test _-Wno-unused-parameter_works - Failed
-- Performing Test _-O0_works
-- Performing Test _-O0_works - Failed
-- Performing Test _-Wno-deprecated_works
-- Performing Test _-Wno-deprecated_works - Failed
-- Performing Test _-fno-omit-frame-pointer_works
-- Performing Test _-fno-omit-frame-pointer_works - Failed

```

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 2, 2024, 6:42pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/4 "2024-10-02T18:42:52Z")

</div>

You could try a test for just one flag (instead of the loop in the function), and run the CMake with `--debug-trycompile`. That will ensure that the CMakeList and Makefile used by CMake for the `try_compile()` inside `check_cxx_compiler_flag()` remain on disk, and you can then inspect/build them manually. It might help you figure out what’s going wrong.

The docs of `check_cxx_compiler_flag()` mention that variables like `CMAKE_CXX_FLAGS` get passed along and can skew the result, you might want to rule that out as a possible cause.

---

<div class="post-metadata">

### Author: ![obioradiegwu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/22d042/32.png) [@obioradiegwu](https://discourse.cmake.org/u/obioradiegwu)
#### Post date: [October 2, 2024, 8:49pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/5 "2024-10-02T20:49:44Z")

</div>

Hi @Angew that was helpful. I can now see the error clearly after adding --debug-trycompile

```auto
Run Build Command(s):/usr/bin/gmake -f Makefile cmTC_67e05/fast && /usr/bin/gmake -f CMakeFiles/cmTC_67e05.dir/build.make CMakeFiles/cmTC_67e05.dir/build
gmake[1]: Entering directory '/apps/qtg/home/valentine/projects/bluebox/cmake-build-debug/CMakeFiles/CMakeTmp'
Building CXX object CMakeFiles/cmTC_67e05.dir/src.cxx.o
/opt/rh/gcc-toolset-13/root/usr/bin/c++ -pthread -latomic -D_GLIBCXX_USE_CXX11_ABI=1 -D_-Wcast-qual_works -Wcast-qual -std=gnu++20 -o CMakeFiles/cmTC_67e05.dir/src.cxx.o -c /apps/qtg/home/valentine/projects/bluebox/cmake-build-debug/CMakeFiles/CMakeTmp/src.cxx
<command-line>: warning: ISO C++11 requires whitespace after the macro name
Linking CXX executable cmTC_67e05
/opt/cmake/cmake-3.21.3-linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/cmTC_67e05.dir/link.txt --verbose=1
/opt/rh/gcc-toolset-13/root/usr/bin/c++ -pthread -latomic -D_GLIBCXX_USE_CXX11_ABI=1 -Wl,--disable-new-dtags CMakeFiles/cmTC_67e05.dir/src.cxx.o -o cmTC_67e05
/opt/rh/gcc-toolset-13/root/usr/libexec/gcc/x86_64-redhat-linux/13/ld: cannot find -latomic: No such file or directory

```

The obvious issue is that the linker cant find libatomic.so which I can sort but I am also seeing a less fatal issue where we are passing the second variable to `check_cxx_compiler_flag` to the compiler flags in `-D_-Wcast-qual_works` which is odd.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [October 2, 2024, 8:58pm UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/6 "2024-10-02T20:58:17Z")

</div>

> [@obioradiegwu](#):
>
> I am also seeing a less fatal issue where we are passing the second variable to `check_cxx_compiler_flag` to the compiler flags in `-D_-Wcast-qual_works` which is odd.

I believe that’s CMake’s doing, and as such I don’t expect that to be an issue. Quoting docs of [`CheckSourceCompiles`](https://cmake.org/cmake/help/latest/module/CheckSourceCompiles.html) (which is used internally by the flag check mechanism):

> A definition for the name specified by `<resultVar>` will also be added automatically.

---

<div class="post-metadata">

### Author: ![obioradiegwu](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/o/22d042/32.png) [@obioradiegwu](https://discourse.cmake.org/u/obioradiegwu)
#### Post date: [October 3, 2024, 8:58am UTC](https://discourse.cmake.org/t/common-patterns-fail-regex-error-on-running-cmake/12671/7 "2024-10-03T08:58:08Z")

</div>

Thanks for all your help @Angew . I think I am fine now.
