Cxx.jl icon indicating copy to clipboard operation
Cxx.jl copied to clipboard

Figure out what to do about -frtti libraries

Open Keno opened this issue 10 years ago • 13 comments

Some libraries a user might want to load have RTTI enabled and some don't. Figure out what do to about that.

Keno avatar Sep 27 '15 20:09 Keno

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.

nstiurca avatar Sep 22 '16 18:09 nstiurca

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.

Keno avatar Sep 22 '16 18:09 Keno

Sorry if this is discussed somewhere already, but what's wrong with enabling RTTI by default?

nstiurca avatar Sep 22 '16 18:09 nstiurca

You can't interface with libraries that are built with RTTI disabled.

Keno avatar Sep 22 '16 18:09 Keno

@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?

oschulz avatar Nov 15 '16 22:11 oschulz

LLVM disabled RTTI.

Keno avatar Nov 15 '16 22:11 Keno

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.

Keno avatar Nov 15 '16 22:11 Keno

How much work would that be?

nstiurca avatar Nov 16 '16 02:11 nstiurca

Very little. It would be a bit unwieldy to use though, as I mentioned. Perhaps better than nothing though.

Keno avatar Nov 16 '16 03:11 Keno

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?

oschulz avatar Nov 16 '16 08:11 oschulz

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?

oschulz avatar Nov 16 '16 08:11 oschulz

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.

stevengj avatar May 18 '20 03:05 stevengj

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.

Gnimuc avatar May 18 '20 06:05 Gnimuc