Hi,
the interpreter of ROOT6 is based on a real compiler and, as such, it looks for all symbols before running the code. So it is somehow “too late” to load the library at runtime since the symbols inside it are needed at compile time.
Now, there are several ways out. The first one, which is the one I recommend, is to use rootmpafiles. These allow ROOT to autoload the libraries needed for running the code and to parse the necessary headers. Creating a rootmapfile is very easy: just use the -rmf switch or --rootmap in rootcling or genreflex respectively.
In case libFoo is a library you did not build and you want to use it interactively I think the best option is to
- Include the header (as you correctly did)
- Use the R__LOAD_LIBRARY(libFoo.dylib) macro: this will trigger the loading of the library at parsing time, therefore in time for letting cling finding the symbols necessary for the compilation
In ROOT5 your code was working since the interpreter, CINT, was interpreting the code line by line.
Cheers