ROOT + java +X11 + thread = crash


I am trying to run some ROOT code from a java application that uses swing. I have observed the following:

  • if a ROOT library is merely loaded (no ROOT function called yet)
  • if a thread is running some swing code

then I get a segmentation fault after a while. The problem does not appear if it is not a ROOT library, or if it is a thread not running swing code, or if swing code is not threaded. (problem with X11?)

I am attaching a very simple program that demonstrates the feature. Run with: javac && java RootCrash

[code]import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class RootCrash {
// there should be /usr/lib and /usr/lib/root in LD_LIBRARY_PATH
public static void main(String[] args) {
System.loadLibrary(“Core”); // line commented = no crash
// There is no problem with non-ROOT librairies
// we create a thread to avoid being blocked in setVisible call
new Thread() {
public void run() {
// we create a JFrame to force the creation of the Event Dispatch Thread
JFrame frame = new JFrame();
for(int i = 0; i < 20000000; i++) {
// interact with the EDT by sending it some jobs.
// block commented = no crash
SwingUtilities.invokeLater(new Runnable() {
public void run() {
// indicates whether we passed invokeLater before crash
// (it appears it is never the case)

My ROOT version is 5.11/02, and java is sun 1.5.0_06.

Any suggestions to solve this problem are very welcome!


Don’t manage to run it:

(macrdm) [154] java -Djava.library.path=/Users/rdm/root/lib RootCrash
Exception in thread “main” java.lang.UnsatisfiedLinkError: no Core in java.library.path
at java.lang.ClassLoader.loadLibrary(
at java.lang.Runtime.loadLibrary0(
at java.lang.System.loadLibrary(
at RootCrash.main(

ROOT library path is also in LD_LIBRARY_PATH and DYLD_LIBRARY_PATH.
This is on MacOS X with the same version of Java as you use.

– Fons


I have no experience with mac, so I don’t know why you cannot load libCore…

The system I ran this test on is Linux


Dear Fons,
on Mac the way jni libraries are build is a little bit different so the test cannot be run exactly in the same way that was presented in the post by Pierre-Francois Giraud.

In order to reproduce the failure you need to create your own jnilib (an almost empty one will be fine) which is linked to ROOT libraries.

The options that I’m using (I took quite a lot of them from ROOT Makefile :wink: ) for building a dynamic library on my MAC, are shown here below:

MACOSX_MINOR  := $(shell sw_vers -productVersion | cut -d'.' -f2)
PLATFORM      := macosx

# compiler
CXX           := c++
CXXFLAGS      := -O -pipe -Wall -W -Woverloaded-virtual

# linker
ifeq ($(MACOSX_MINOR),3)
   UNDEFOPT   := dynamic_lookup
   LD         := MACOSX_DEPLOYMENT_TARGET=10.3 c++
   UNDEFOPT   := suppress
   LD         := c++

ifeq ($(DLLSUFFIX), dylib)
   LDFLAGS    := -dynamiclib -flat_namespace -undefined $(UNDEFOPT)
   LDFLAGS    := -bundle -undefined $(UNDEFOPT) -O -Xlinker - bind_at_load -flat_namespace

You have to add (when you link) the root libraries , using
root-config --glibs for example.

Once the .so library is created you can copy it into a .jnilib library
and then use it from Java.

Then you will be able to reproduce the same crash. If you change the Makefile and you try to link another library (Qt for example) you will have no problems in running the example.

Thanks in advance for any help you can provide, and tell me if my instructions were not clear enough in order to test the code .