Unrecognized command-line option building LLVM

Viewed 60

I'm building an older version of llvm, 3.5.1, on an ubuntu virtual machine. I downloaded the source code from here (https://releases.llvm.org/download.html#3.5.1)

After downloading the source code I followed the instructions here (https://llvm.org/docs/GettingStarted.html) I made a build directory in which I ran "$cmake -G Ninja -DCMAKE_BUILD_TYPE=debug ../llvm" to build it with Ninja. This works as intended.

However when I try to run "$cmake --build ." to actually build it, it fails with the error "cc: error: unrecognized command-line option '-fcolor-diagnostics' "

Any help is appreciated!

My gcc version is: (Ubuntu 11.2.0-19ubuntu1) 11.2.0

Here is the extended error message

[1/1441] Building C object lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o
/usr/bin/cc -DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/isaac/llvm/build/lib/Support -I/home/isaac/llvm/llvm/lib/Support -I/home/isaac/llvm/build/include -I/home/isaac/llvm/llvm/include -fPIC -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wno-comment -fcolor-diagnostics -g -MD -MT lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o -MF lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o.d -o lib/Support/CMakeFiles/LLVMSupport.dir/ConvertUTF.c.o -c /home/isaac/llvm/llvm/lib/Support/ConvertUTF.c
cc: error: unrecognized command-line option 'fcolor-diagnostics'

1 Answers

At this version of LLVM, -fcolor-diagnostics gets added with clang as the compiler and Ninja as the generator. That said, since you're using Ninja, your system's compiler must not support the flag. A quick test to prevent the flag's application would be to skip Ninja and use the default Makefile generation. Try using

cmake -DCMAKE_BUILD_TYPE=Debug ../llvm

To help with debugging, the Getting Started instructions at an un-versioned URL are more appropriate for relatively current versions of LLVM. In this situation, version specific instructions for 3.x would be better. You can find version specific instructions at https://releases.llvm.org/3.5.2/docs/GettingStarted.html. Unfortunately, at the 3.x timeframe, the sources were split among repos and bundled in separate tarballs.

The primary difference in the build process from the 3.x timeframe is the unification of the LLVM source code (where LLVM is combined with the runtime, clang, lldb, etc). Since the unified sources will still build older versions, the symlinks of multiple tarball contents can be skipped while being easier to work with. The unified sources for 3.5.1 can be obtained by cloning https://github.com/llvm/llvm-project and checking out tag llvmorg-3.5.1.

Could you try to bootstrap the compiler by using the compiled clang from llvm.org for Ubuntu 12.04, precompiled LLVM 3.4.2. This tooling is for the purpose of aligning your tools 2with the version you're targeting, 3.5.1? I'd also recommend building with CMAKE_BUILD_TYPE=Release until a good build is confirmed. Using

CC=/bootstrap_path/clang CXX=/bootstrap_path/clang++ cmake -GNinja -DCMAKE_BUILD_TYPE=Release ../llvm

will be sufficient to swap in clang as the bootstrap compiler which will support the -fcolor-diagnostics.

Related