Figure out what to do about -frtti libraries
Some libraries a user might want to load have RTTI enabled and some don't. Figure out what do to about that.
So I ran into trying to wrap a library that needs/uses RTTI, and I can't import it in Cxx.jl. The particular library is libroscpp, part of ROS. Actually, Libdl.dlopen("/opt/ros/kinetic/lib/libroscpp.so") worked fine, but cxxinclude("ros/ros.h") resulted in the following errors:
In file included from :1:
In file included from /opt/ros/kinetic/include/ros/ros.h:45:
In file included from /opt/ros/kinetic/include/ros/node_handle.h:32:
/opt/ros/kinetic/include/ros/publisher.h:85:22: error: cannot use typeid with -fno-rtti
m.type_info = &typeid(M);
^
In file included from :1:
In file included from /opt/ros/kinetic/include/ros/ros.h:45:
In file included from /opt/ros/kinetic/include/ros/node_handle.h:33:
In file included from /opt/ros/kinetic/include/ros/subscriber.h:33:
/opt/ros/kinetic/include/ros/subscription_callback_helper.h:149:12: error: cannot use typeid with -fno-rtti
return typeid(NonConstType);
So I would like to echo the call in #264 to have some way of enabling RTTI in Cxx.jl.
You can manually set these lines:
https://github.com/Keno/Cxx.jl/blob/master/src/bootstrap.cpp#L1319-L1320
I still don't know what to do in the general case though.
Sorry if this is discussed somewhere already, but what's wrong with enabling RTTI by default?
You can't interface with libraries that are built with RTTI disabled.
@Keno, until there's a generic solution, would you consider changing the default to RTTI-enabled? After all, compilers usually enable RTTI by default, and parts of the C++ language don't work without it.
I also have a feeling that most libraries either need RTTI or at least don't disable it. But I have to admit that I'm biased, as ROOT needs RTTI (and I need ROOT). ;-)
Just to get a better picture of this: Who knows which popular libraries are usually built with RTTI disabled?
LLVM disabled RTTI.
That said, there's an argument to be made that this should be settable on a per CompilerInstance basis, such that at least there's a way to do it without rebuilding Cxx.
How much work would that be?
Very little. It would be a bit unwieldy to use though, as I mentioned. Perhaps better than nothing though.
LLVM disabled RTTI.
Interesting, thanks, I didn't know that. Looks like they roll their own (apparently more lightweight) version of it. Clang itself does enable RTTI by default though, right?
It would be a bit unwieldy to use though, as I mentioned. Perhaps better than nothing though.
Would it have to be done before using Cxx (e.g. via an env variable JULIA_CXX_RTTI or so), or could a package set it after loading Cxx?
Would be nice to have a better resolution to this issue. (I was trying to call the GNU Octave libraries and ran into this, because they require RTTI).
Currently, the workaround is to set ENV["JULIA_CXX_RTTI"]=1 before building or using Cxx, so basically it has to be set globally in startup.jl or similar. This is non-composable, since packages that require different RTTI settings cannot co-exist.
I guess we can reimplement the following configuration function in pure Julia. All we need is to expose a thin C wrapper over Clang's CompilerInstance C++ API. https://github.com/JuliaInterop/Cxx.jl/blob/aad6940e9f31a3801bc87a8bfa6d35defbb492c3/src/bootstrap.cpp#L1415-L1497
I actually tried to make such wrapper a while ago, but LangOpts has a long list, maybe it's more feasible to just expose a subset of options.