Clang unable to find ROOT headers


ROOT Version: 6.22.08
Platform: MaxOSX 11.2.3 Big Sur
Compiler: Clang


Hello!
Newbie here, I recently installed ROOT via the binary on the site (clang 12 for Xcode 12) and I am able to use it after having set the correct PATH variables. Nevertheless, I can’t compile a c++ program that invokes ROOT libraries because Clang fails in finding the proper headers. As an example I get this message as an error

Apple clang version 12.0.0 (clang-1200.0.32.29)

Target: x86_64-apple-darwin20.3.0

Thread model: posix

InstalledDir: /Library/Developer/CommandLineTools/usr/bin

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"

"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name slyt1.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=11.1 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -fdeprecated-macro -fdebug-compilation-dir "/Users/mac 1" -ferror-limit 19 -fmessage-length 80 -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/_f/2gdjhgp139gcv4gdv2ggp9y00000gp/T/slyt1-9bc1bf.o -x c++ slyt1.cpp

clang -cc1 version 12.0.0 (clang-1200.0.32.29) default target x86_64-apple-darwin20.3.0

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"

ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"

#include "..." search starts here:

#include <...> search starts here:

/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1

/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include

/Library/Developer/CommandLineTools/usr/include

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)

End of search list.

**slyt1.cpp:5:10:** **fatal error:** **'TH1F.h' file not found**

#include "TH1F.h"

**^~~~~~~~**

1 error generated.

Before posting here, I properly installed Xcode and the command developer tools via

xcode-select --install

I also tried to use g++ as a compiler but of course failed in trying since ROOT uses clang. After some unconclusive research on this forum I believe the problem is in the compiler, since if I launch root from terminal I can use it without any problems. Any idea on how I can fix this?
Thanks in advance.

So I suppose you executed the script thisroot.sh to define all the environment variables as explained here. Also, can you show the command you used to compile ?

@couet

Yes, I also defined the environment variables in

.bashrc

In this way I am able to run root from every directory by typing

(base) Mac-5:~ nicola$ root
   ------------------------------------------------------------------
  | Welcome to ROOT 6.22/08                        https://root.cern |
  | (c) 1995-2020, The ROOT Team; conception: R. Brun, F. Rademakers |
  | Built for macosx64 on Mar 10 2021, 14:20:04                      |
  | From tags/v6-22-08@v6-22-08                                      |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q'       |
   ------------------------------------------------------------------

root [0] 

The problem is, whenever I write a c++ program and try to compile it like this

(base) Mac-5:~ nicola$ clang++ -o slyt1 slyt1.cpp $(root-config --libs --cflags)

usage: dirname path

usage: dirname path

**slyt1.cpp:5:10:** **fatal error:** **'TH1F.h' file not found**

#include "TH1F.h"

**^~~~~~~~**

1 error generated.

I also tried to use different syntax

(base) Mac-5:~ nicola$ clang++ -o slyt1 slyt1.cpp `root-config --libs --cflags`
usage: dirname path
usage: dirname path
slyt1.cpp:5:10: fatal error: 'TH1F.h' file not found
#include "TH1F.h"
         ^~~~~~~~
1 error generated.

as suggested in other posts on the forum, but it doesn’t make any difference.

Of course if I try to use g++

(base) Mac-5:~ nicola$ g++ -o slyt1 slyt1.cpp `root-config --libs --cflags`
usage: dirname path
usage: dirname path
g++-10: error: unrecognized command-line option '-stdlib=libc++'
g++-10: error: unrecognized command-line option '-stdlib=libc++'

So what should I do?

Again, by looking at the verbose content of the clang error it seems the compiler doesn’t find ROOT headers:

usage: dirname path
usage: dirname path
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"
 "/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name slyt1.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=11.1 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I /include -stdlib=libc++ -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -std=c++11 -fdeprecated-macro -fdebug-compilation-dir "/Users/mac 1" -ferror-limit 19 -fmessage-length 157 -pthread -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/_f/2gdjhgp139gcv4gdv2ggp9y00000gp/T/slyt1-e283b6.o -x c++ slyt1.cpp
clang -cc1 version 12.0.0 (clang-1200.0.32.29) default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
 /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
 /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
 /Library/Developer/CommandLineTools/usr/include
 /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
End of search list.
slyt1.cpp:5:10: fatal error: 'TH1F.h' file not found
#include "TH1F.h"
         ^~~~~~~~
1 error generated.

Thanks for your help.

Try:

`root-config --cxx --cflags` -o slyt1 slyt1.cpp `root-config --libs`

@Wile_E_Coyote

I get the following error:

(base) Mac-5:~ nicola$ clang++ `root-config --cxx --cflags` -o slyt1 slyt1.cpp `root-config --libs` -v
usage: dirname path
usage: dirname path
usage: dirname path
usage: dirname path
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
clang: error: no such file or directory: 'c++'
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"

Where do you see “clang++” in my previous post?

sorry, but the error is still the same

(base) Mac-5:~ nicola$ `root-config --cxx --cflags` -o slyt1 slyt1.cpp `root-config --libs` -v
usage: dirname path
usage: dirname path
usage: dirname path
usage: dirname path
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: x86_64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/v1"
"/Library/Developer/CommandLineTools/usr/bin/clang" -cc1 -triple x86_64-apple-macosx11.0.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -Werror=implicit-function-declaration -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name slyt1.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mframe-pointer=all -fno-strict-return -masm-verbose -munwind-tables -target-sdk-version=11.1 -target-cpu penryn -dwarf-column-info -debugger-tuning=lldb -target-linker-version 609.8 -v -resource-dir /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -I /include -stdlib=libc++ -stdlib=libc++ -internal-isystem /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1 -internal-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include -internal-isystem /Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include -internal-externc-isystem /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include -internal-externc-isystem /Library/Developer/CommandLineTools/usr/include -Wno-reorder-init-list -Wno-implicit-int-float-conversion -Wno-c99-designator -Wno-final-dtor-non-final-class -Wno-extra-semi-stmt -Wno-misleading-indentation -Wno-quoted-include-in-framework-header -Wno-implicit-fallthrough -Wno-enum-enum-conversion -Wno-enum-float-conversion -std=c++11 -fdeprecated-macro -fdebug-compilation-dir "/Users/mac 1" -ferror-limit 19 -fmessage-length 80 -pthread -stack-protector 1 -fstack-check -mdarwin-stkchk-strong-link -fblocks -fencode-extended-block-signature -fregister-global-dtors-with-atexit -fgnuc-version=4.2.1 -fobjc-runtime=macosx-11.0.0 -fcxx-exceptions -fexceptions -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/_f/2gdjhgp139gcv4gdv2ggp9y00000gp/T/slyt1-f2c001.o -x c++ slyt1.cpp
clang -cc1 version 12.0.0 (clang-1200.0.32.29) default target x86_64-apple-darwin20.3.0
ignoring nonexistent directory "/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/local/include"
ignoring nonexistent directory "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1
/Library/Developer/CommandLineTools/usr/lib/clang/12.0.0/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include
/Library/Developer/CommandLineTools/usr/include
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks (framework directory)
End of search list.
**slyt1.cpp:5:10:** **fatal error:** **'TH1F.h' file not found**
#include "TH1F.h"
**^~~~~~~~**
1 error generated.

Inspect paths which appear in the output of:

root-config --incdir # should contain ROOT includes
root-config --cxx --cflags
root-config --libdir # should contain ROOT libraries
root-config --libs

Indeed, that’s the case:

(base) Mac-5:~ nicola$ root-config --incdir
usage: dirname path
usage: dirname path
/include
(base) Mac-5:~ nicola$ root-config --cxx --cflags
usage: dirname path
usage: dirname path
c++ -stdlib=libc++ -pthread -std=c++11 -m64 -I/include
(base) Mac-5:~ nicola$ root-config --libdir
usage: dirname path
usage: dirname path
/lib
(base) Mac-5:~ nicola$ root-config --libs
usage: dirname path
usage: dirname path
-L/lib -lCore -lImt -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lROOTVecOps -lTree -lTreePlayer -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -lROOTDataFrame -stdlib=libc++ -lpthread -lm -ldl

I guess those path are referred to the position of ROOT, right?

To me, the errors “usage: dirname path” suggest that your login shell has problems with “root-config”.
Can you try to run “bash” and then from inside of it execute “root-config ...”.

For instance the first path,

$ROOTSYS/include/

contains the

TH1F.h

header, so I guess the problem is not in ROOT

Do they return the same:

echo ${ROOTSYS}
root-config --prefix

Unfortunately, same error

(base) Mac-5:/ nicola$ bash
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ `root-config --cxx --cflags` -o slyt1 slyt1.cpp `root-config --libs`
usage: dirname path
usage: dirname path
usage: dirname path
usage: dirname path
slyt1.cpp:5:10: fatal error: 'TH1F.h' file not found
#include "TH1F.h"
         ^~~~~~~~
1 error generated.

No, they don’t:

bash-3.2$ echo ${ROOTSYS}
/Users/mac 1/root_v6.22.08
bash-3.2$ root-config --prefix
usage: dirname path
usage: dirname path

So, I suspected it was “zsh” … try to run "bash" and then:

export SHELL="/bin/bash" # or maybe /usr/bin/bash
root-config --prefix

BTW. Make the “bash” your default login shell, if you want fewer problems with somebody’s scripts.

Strange…, here is the output:

bash-3.2$ export SHELL="/bin/bash"
bash-3.2$ root-config --prefix
usage: dirname path
usage: dirname path

One more thing that I now noticed … ROOT is known to trip on paths which contain spaces. Make sure that you do NOT use “.../mac 1/...” (maybe this is the origin of the “usage: dirname path” errors).

This solved the issue, I can’t express how grateful I am

after eliminating that space in ‘Mac 1’

Try the various “root-config --...” commands from my previous posts and make sure that they return paths consistent with “echo ${ROOTSYS}”.