I'm attempting to compile a binary from source, but keep running into an error while doing so.
$ cmake --build ./\[binary_dir\]/
[ 0%] Building C object [binary_dir]/CMakeFiles/ZIPLIB.dir/extlibs/bzip2/bcompress.c.o
cc: error: unrecognized command line option ‘-std=c 20’; did you mean ‘-std=c 2a’?
make[2]: *** [[binary_dir]/CMakeFiles/ZIPLIB.dir/build.make:154: [binary_dir]/CMakeFiles/ZIPLIB.dir/extlibs/bzip2/bcompress.c.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:307: [binary_dir]/CMakeFiles/ZIPLIB.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
Specifically, "cc: error: unrecognized command line option ‘-std=c 20’; did you mean ‘-std=c 2a’?."
I suspect this has to do with using the incorrect version of gcc; I have multiple version installed but believe I need to be using the latest, or at least 11.1.0. I have these versions installed:
$ ls -l /usr/bin/gcc*
lrwxrwxrwx 1 root root 5 Mar 20 2020 /usr/bin/gcc -> gcc-9
lrwxrwxrwx 1 root root 23 May 29 2021 /usr/bin/gcc-10 -> x86_64-linux-gnu-gcc-10
lrwxrwxrwx 1 root root 23 Apr 28 2021 /usr/bin/gcc-11 -> x86_64-linux-gnu-gcc-11
lrwxrwxrwx 1 root root 22 Mar 9 12:57 /usr/bin/gcc-9 -> x86_64-linux-gnu-gcc-9
lrwxrwxrwx 1 root root 8 Mar 20 2020 /usr/bin/gcc-ar -> gcc-ar-9
lrwxrwxrwx 1 root root 26 May 29 2021 /usr/bin/gcc-ar-10 -> x86_64-linux-gnu-gcc-ar-10
lrwxrwxrwx 1 root root 26 Apr 28 2021 /usr/bin/gcc-ar-11 -> x86_64-linux-gnu-gcc-ar-11
lrwxrwxrwx 1 root root 25 Mar 9 12:57 /usr/bin/gcc-ar-9 -> x86_64-linux-gnu-gcc-ar-9
lrwxrwxrwx 1 root root 8 Mar 20 2020 /usr/bin/gcc-nm -> gcc-nm-9
lrwxrwxrwx 1 root root 26 May 29 2021 /usr/bin/gcc-nm-10 -> x86_64-linux-gnu-gcc-nm-10
lrwxrwxrwx 1 root root 26 Apr 28 2021 /usr/bin/gcc-nm-11 -> x86_64-linux-gnu-gcc-nm-11
lrwxrwxrwx 1 root root 25 Mar 9 12:57 /usr/bin/gcc-nm-9 -> x86_64-linux-gnu-gcc-nm-9
lrwxrwxrwx 1 root root 12 Mar 20 2020 /usr/bin/gcc-ranlib -> gcc-ranlib-9
lrwxrwxrwx 1 root root 30 May 29 2021 /usr/bin/gcc-ranlib-10 -> x86_64-linux-gnu-gcc-ranlib-10
lrwxrwxrwx 1 root root 30 Apr 28 2021 /usr/bin/gcc-ranlib-11 -> x86_64-linux-gnu-gcc-ranlib-11
lrwxrwxrwx 1 root root 29 Mar 9 12:57 /usr/bin/gcc-ranlib-9 -> x86_64-linux-gnu-gcc-ranlib-9
If that's the issue, how can I specify which version of gcc to use? Would that happen in the makefile/cmakelist itself, as a path which I need to specify in my environment, or as a flag applied when calling cmake?
Or does the error suggest another solution?
CodePudding user response:
Presuming you are in a build directory:
You can set CMAKE_C_COMPILER when you run the original call to cmake.
cmake -DCMAKE_C_COMPILER=/usr/bin/gcc-11 ..
cmake --build .