从Java中调用Xinitthreads。Gnuplot错误。

4

我试图在我的Scala代码中启动gnuplot。

我使用ProcessBuilder来启动外部进程。

但是,当我启动gnuplot时:

gnuplot -p <generated script>

所以,就像:

Seq("gnuplot", "-p", scriptname).!

I get:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
gnuplot: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

似乎我需要调用XInitThreads 我的问题是:
  • 如何从Java调用该本地方法(我假设我可以在我的Scala代码中使用它),或者直接从Scala中调用该方法?
  • 是否可能存在其他问题?
编辑: 我不明白为什么要做这样简单的事情会那么麻烦。我不想花一整天时间深入细节来绘制一个该死的图表。 我简单地转而使用JFreeChart。

你能澄清一下你是如何生成子进程的吗?我假设如果你从shell中运行命令(使用生成的脚本),它可以正常工作,对吗?你能提供一个启动失败的Scala代码片段来启动该进程吗? - Alexandros
1
从这个线程开始看起:https://mail.gnome.org/archives/gtk-list/2000-October/msg00021.html 以了解发生了什么。JVM 运行您的代码是否来自已经打开 X 连接的其他进程(在这种情况下,您需要往上游挖掘)?此外,gnuplot 本身使用哪个工具包进行渲染?例如,请参见 http://gnuplot.10905.n7.nabble.com/crash-when-using-wxt-in-Ubuntu-12-04-td17318.html 的 XInitThreads 调用失败。 - Alexandros
最后一点评论:据我所知,当JVM访问X时,它总是足够早地调用这个函数;所以我认为不是你在代码中做的事情导致了这个问题,而且自己调用它也没有意义(每个客户端必须足够早地调用它)。很抱歉我不能提供更多帮助...祝你好运! - Alexandros
1个回答

2
您可以尝试来自Eggplanticus的提示,链接在此处:这里
fixXInitThreads.cpp
#include <Xlib.h>
#include <stdio.h>
class a{public: a() { XInitThreads(); }};a X;

使用以下命令进行编译:
g++ -o libfixXInitThreads.so -shared -fPIC -Wl,-soname,libxx.so -L/usr/lib/X11 -I/usr/include/X11 fixXInitThreads.cpp -lX11

main()函数的第一行添加以下代码:
System.loadLibrary("fixXInitThreads");
或者使用以下代码加载本地路径下的库文件:
System.load(System.getProperty("user.dir")+"/libfixXInitThreads.so");


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接