clang finds errors in its own header files

Hi Don,

I removed the extra “-I” directives but I still get the same result.

Hi Paul:

Why are you explicitly including …/c++/4.2.1?

If clang was compiled correctly, it should be able to find it’s own c++ headers – on OSX, that’s most likely libc++ headers. Try running:

clang++ -v -c -x c++ - < /dev/null

hth…
don

I am writing a parser for c++.

I am developing on a Mac. OS X Sierra 10.12.1

I am frustrated by the fact that I cannot compile even the simplest c++ code because clang 4.0 finds errors in the clang headers themselves! for example:

#include “clang/AST/ASTContext.h”
#include “clang/AST/ASTConsumer.h”
#include "clang/AST/
#include “clang/RecursiveASTVisitor.h”
#include “clang/Frontend/ASTConsumers.h”
#include “clang/Frontend/FrontendActions.h”
#include “clang/Frontend/CompilerInstance.h”
#include “clang/Tooling/CommonOptionsParser.h”
#include “clang/Tooling/Tooling.h”
#include “clang/Rewrite/Core/Rewriter.h”
#include “llvm/Support/raw_ostream.h”
#include
#include

int main( void )
{
return 0;
}


I have been trying to solve this by examining others’ Makefiles but to no avail.
This is the result of my latest effort:

50%] Building CXX object CMakeFiles/testProject.dir/main.cpp.o
In file included from /Users/paul/Temp/test/src/main.cpp:1:
In file included from /usr/local/include/clang/AST/AST.h:18:
In file included from /usr/local/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/include/clang/AST/Decl.h:17:
In file included from /usr/local/include/clang/AST/APValue.h:18:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
In file included from /usr/local/include/llvm/ADT/APInt.h:20:
/usr/local/include/llvm/Support/MathExtras.h:248:1: error: unknown type name ‘constexpr’
constexpr inline uint32_t Hi_32(uint64_t Value) {
^
/usr/local/include/llvm/Support/MathExtras.h:248:11: error: expected unqualified-id
constexpr inline uint32_t Hi_32(uint64_t Value) {
^
/usr/local/include/llvm/Support/MathExtras.h:253:1: error: unknown type name ‘constexpr’
constexpr inline uint32_t Lo_32(uint64_t Value) {
^
/usr/local/include/llvm/Support/MathExtras.h:253:11: error: expected unqualified-id
constexpr inline uint32_t Lo_32(uint64_t Value) {
^
/usr/local/include/llvm/Support/MathExtras.h:259:1: error: unknown type name ‘constexpr’
constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) {
^
/usr/local/include/llvm/Support/MathExtras.h:259:11: error: expected unqualified-id
constexpr inline uint64_t Make_64(uint32_t High, uint32_t Low) {
^
/usr/local/include/llvm/Support/MathExtras.h:264:23: error: unknown type name ‘constexpr’
template constexpr inline bool isInt(int64_t x) {
^
/usr/local/include/llvm/Support/MathExtras.h:264:33: error: expected unqualified-id
template constexpr inline bool isInt(int64_t x) {
^
/usr/local/include/llvm/Support/MathExtras.h:710:10: error: use of undeclared identifier ‘alignTo’
return alignTo(Value, Align) - Value;
^
/usr/local/include/llvm/Support/MathExtras.h:715:23: error: unknown type name ‘constexpr’
template constexpr inline int32_t SignExtend32(uint32_t X) {
^
/usr/local/include/llvm/Support/MathExtras.h:715:33: error: expected unqualified-id
template constexpr inline int32_t SignExtend32(uint32_t X) {
^
In file included from /Users/paul/Temp/test/src/main.cpp:1:
In file included from /usr/local/include/clang/AST/AST.h:18:
In file included from /usr/local/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/include/clang/AST/Decl.h:17:
In file included from /usr/local/include/clang/AST/APValue.h:18:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
/usr/local/include/llvm/ADT/APInt.h:393:14: error: use of undeclared identifier ‘isPowerOf2_64’
return isPowerOf2_64(VAL);
^
/usr/local/include/llvm/ADT/APInt.h:1387:20: error: no member named ‘countTrailingOnes’ in namespace ‘llvm’; did you mean ‘countTrailingZeros’?
return llvm::countTrailingOnes(VAL);

/usr/local/include/llvm/Support/MathExtras.h:111:13: note: 'countTrailingZeros' declared here
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB = ZB_Width) {
^
In file included from /Users/paul/Temp/test/src/main.cpp:1:
In file included from /usr/local/include/clang/AST/AST.h:18:
In file included from /usr/local/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/include/clang/AST/Decl.h:17:
In file included from /usr/local/include/clang/AST/APValue.h:18:
In file included from /usr/local/include/llvm/ADT/APFloat.h:20:
/usr/local/include/llvm/ADT/APInt.h:1399:20: error: no member named 'countPopulation' in namespace 'llvm'
return llvm::countPopulation(VAL);
~~~~~~^
In file included from /Users/paul/Temp/test/src/main.cpp:1:
In file included from /usr/local/include/clang/AST/AST.h:18:
In file included from /usr/local/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/include/clang/AST/Decl.h:17:
In file included from /usr/local/include/clang/AST/APValue.h:18:
/usr/local/include/llvm/ADT/APFloat.h:661:15: error: union member 'IEEE' has a non-trivial copy constructor
IEEEFloat IEEE;
^
/usr/local/include/llvm/ADT/APFloat.h:224:3: note: because type 'llvm::detail::IEEEFloat' has a user-provided copy constructor
IEEEFloat(const IEEEFloat &);
^
/usr/local/include/llvm/ADT/APFloat.h:662:19: error: union member 'Double' has a non-trivial copy constructor
DoubleAPFloat Double;
^
/usr/local/include/llvm/ADT/APFloat.h:617:3: note: because type 'llvm::detail::DoubleAPFloat' has a user-provided copy constructor
DoubleAPFloat(const DoubleAPFloat &RHS);
^
/usr/local/include/llvm/ADT/APFloat.h:750:35: error: too many arguments provided to function-like macro invocation
std::is_same<T, DoubleAPFloat>::value, "");
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__config:596:9: note: macro 'static_assert' defined here
#define static_assert(__b, __m) \
^
In file included from /Users/paul/Temp/test/src/main.cpp:1:
In file included from /usr/local/include/clang/AST/AST.h:18:
In file included from /usr/local/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/include/clang/AST/Decl.h:17:
In file included from /usr/local/include/clang/AST/APValue.h:18:
/usr/local/include/llvm/ADT/APFloat.h:749:5: error: use of undeclared identifier 'static_assert'
static_assert(std::is_same<T, IEEEFloat>::value ||
^
In file included from /Users/paul/Temp/test/src/main.cpp:1:
In file included from /usr/local/include/clang/AST/AST.h:18:
In file included from /usr/local/include/clang/AST/ASTContext.h:18:
In file included from /usr/local/include/clang/AST/ASTTypeTraits.h:20:
In file included from /usr/local/include/clang/AST/Decl.h:17:
In file included from /usr/local/include/clang/AST/APValue.h:20:
In file included from /usr/local/include/llvm/ADT/PointerIntPair.h:18:
/usr/local/include/llvm/Support/PointerLikeTypeTraits.h:45:61: error: 'T' does not refer to a value
enum { NumLowBitsAvailable = detail::ConstantLog2<alignof(T)>::value };
^
/usr/local/include/llvm/Support/PointerLikeTypeTraits.h:40:20: note: declared here
template <typename T> class PointerLikeTypeTraits<T *> {
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [CMakeFiles/testProject.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/testProject.dir/all] Error 2
make: *** [all] Error 2

Hi Don,

I removed the extra "-I" directives but I still get the same result.

This looks somewhat different to me.

In file included from /usr/local/include/llvm/ADT/APInt.h:20:
/usr/local/include/llvm/Support/MathExtras.h:248:1: error: unknown type
name 'constexpr'
constexpr inline uint32_t Hi_32(uint64_t Value) {

You need to specify -std=c++11 (or later) as a compiler option to get
`constexpr` support. You probably want to do that anyway.

-- James

Hi James,

Thanks,

I do include the -std=c++11 as a habit.

I have been trying all afternoon to get this to work.

I am wondering now if there is a step missing which describes the target OS? Xcode links to a number of SDK’s when producing OS X Bundles ( test.app ).

Thanks Nathan.

After adding -stdlib=libc++ I get:

Pauls-iMac:build paul$ clang-4.0 -std=c++11 -stdlib=libc++ -v ../src/main.cpp
clang version 4.0.0 (GitHub - llvm-mirror/clang: Mirror kept for legacy. Moved to https://github.com/llvm/llvm-project d018ab0a692bb12b9b88a24555354d81cdb779dc) (GitHub - llvm-mirror/llvm: Project moved to: https://github.com/llvm/llvm-project 4b0e4b53984a098911fd68282e1b6e87e4c77f48)
Target: x86_64-apple-darwin16.1.0
Thread model: posix
InstalledDir: /usr/local/bin
  "/usr/local/bin/clang-4.0" -cc1 -triple x86_64-apple-macosx10.12.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 274.1 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /usr/local/bin/../lib/clang/4.0.0 -stdlib=libc++ -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /Users/paul/Temp/test/build -ferror-limit 19 -fmessage-length 187 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.12.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/nz/0n84ymfx40z5jr0mk9b58q240000gn/T/main-315802.o -x c++ ../src/main.cpp
clang -cc1 version 4.0.0 based upon LLVM 4.0.0svn default target x86_64-apple-darwin16.1.0
ignoring nonexistent directory "/usr/include/c++/v1"
#include "..." search starts here:
#include <...> search starts here:
  /usr/local/bin/../include/c++/v1
  /usr/local/include
  /usr/local/bin/../lib/clang/4.0.0/include
  /usr/include
  /System/Library/Frameworks (framework directory)
  /Library/Frameworks (framework directory)
End of search list.
  "/usr/bin/ld" -demangle -lto_library /usr/local/lib/libLTO.dylib -no_deduplicate -dynamic -arch x86_64 -macosx_version_min 10.12.0 -o a.out /var/folders/nz/0n84ymfx40z5jr0mk9b58q240000gn/T/main-315802.o -lSystem /usr/local/bin/../lib/clang/4.0.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
   "llvm::DisableABIBreakingChecks", referenced from:
       llvm::VerifyDisableABIBreakingChecks in main-315802.o
ld: symbol(s) not found for architecture x86_64
clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)

Thanks again

You need to link to libLLVMSupport.a.

Thanks Mehdi,

This gets me much closer to success :slight_smile:

However I am still getting 1 unresolved symbol: llvm::DisableABIBreakingChecks

Any further thoughts?

Thanks again for your help

Paul

What does this print: nm libLLVMSupport.a | grep ABIBreaking

My latest compile result:

Undefined symbols for architecture x86_64:
“llvm::itaniumDemangle(char const*, char*, unsigned long*, int*)”, referenced from:
llvm::sys::PrintStackTrace(llvm::raw_ostream&) in libLLVMSupport.a(Signals.cpp.o)
“_del_curterm”, referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
“_set_curterm”, referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
“_setupterm”, referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
“_tigetnum”, referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libLLVMSupport.a(Process.cpp.o)
ld: symbol(s) not found for architecture x86_64

Thanks for all the help

Paul

This is libLLVMDemangle.a

You should be able to find these dependency yourself by using nm on the various lib.

But if you’re trying to interact with LLVM, you should try to use llvm-config to get the right flags: http://llvm.org/docs/CommandGuide/llvm-config.html