一般:
当使用 XULRunner 15 调用 XRE_InitEmbedding2 函数时,我总是在 Linux 上收到 SIGSEGV。
详细信息:
我正在尝试将 Mozilla(XULRunner 15.05b 64 位)浏览器组件嵌入到我在 Fedora 12 64 位上的 GTK 应用程序中。我创建了 Eclipse 项目,将其配置为使用所有必需的 XULRunner 库并包含文件并成功构建它。
这是应用程序代码:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include "nsXPCOM.h"
#include "nsXPCOMGlue.h"
#include "nsEmbedString.h"
#include "nsXULAppAPI.h"
#include "nsILocalFile.h"
using namespace std;
XRE_InitEmbedding2Type XRE_InitEmbedding2Delegate;
int main(int argc, char** argv) {
nsDynamicFunctionLoad kXRESymbols[] = {
{"XRE_InitEmbedding2", (NSFuncPtr*) &XRE_InitEmbedding2Delegate},
{0, 0}
};
GtkWidget *window;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_show(window);
nsresult rv = XPCOMGlueStartup("/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin/libxpcom.so");
if (NS_FAILED(rv)) {
return rv;
}
rv = XPCOMGlueLoadXULFunctions(kXRESymbols);
if (NS_FAILED(rv)) {
return rv;
}
nsILocalFile *libXULDir;
rv = NS_NewNativeLocalFile(nsEmbedCString("/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin"), PR_FALSE, &libXULDir);
if (NS_FAILED(rv)) {
return rv;
}
rv = XRE_InitEmbedding2Delegate(libXULDir, libXULDir, nsnull);
if (NS_FAILED(rv)) {
return rv;
}
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
我使用以下命令行编译了这个应用程序:
make all
Building file: ../src/JavaXPCOMTest.cpp
Invoking: GCC C++ Compiler
g++ -DXPCOM_GLUE_USE_NSPR=1 -DXPCOM_GLUE=1 -I/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/include -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -O0 -g3 -Wall -c -fmessage-length=0 -std=gnu++0x `pkg-config --cflags --libs gtk+-2.0` -MMD -MP -MF"src/JavaXPCOMTest.d" -MT"src/JavaXPCOMTest.d" -o"src/JavaXPCOMTest.o" "../src/JavaXPCOMTest.cpp"
Finished building: ../src/JavaXPCOMTest.cpp
Building target: JavaXPCOMTest
Invoking: GCC C++ Linker
g++ -L/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/lib -L/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin -Wl,-rpath-link,/home/Victor/Projects/JavaXPCOM/xulrunner-sdk/bin -o"JavaXPCOMTest" ./src/JavaXPCOMTest.o -lxpcomglue -lstdc++ `pkg-config --cflags --libs gtk+-2.0`
Finished building target: JavaXPCOMTest
当我运行这个应用程序时,我在使用以下调用堆栈调用 XRE_InitEmbedding2Delegate 函数时收到 SIGSEGV:
Thread [1] 15449 (Suspended : Signal)
_dl_fixup() at 0x3dbd60dbec
_dl_runtime_resolve() at 0x3dbd614315
0x7fffee4031d3
0x7fffee429209
0x7fffee429223
0x7fffee42a943
0x7fffee42b7ae
0x7fffee42bb25
NS_InitXPCOM2_P() at 0x7fffee4063a9
XRE_InitEmbedding2() at 0x7fffed998ce7
<...more frames...>
有人在使用 XULRunner 15 的 Linux 平台上重现过类似问题吗?也许我使用了一些错误的命令行参数或者忘记在命令行中包含一些东西。
最佳答案
可能与此有关unanswered bug report :
Since Firefox 10 we get a crash while creating (constructor) the MozApp-object. More precisely the crash is by calling the API 'XRE_InitEmbedding2()' (its function- pointer is valid!) ... Up to version 9 of Firefox we do not have this crash - only since version 10. You can find details in the following bug report here: https://bugzilla.mozilla.org/show_bug.cgi?id=724822
您或许可以使用嵌入式 API。但是无论如何使用 gtkmozembed 都是注定要失败的,因为作者正在撤回对它的所有支持,因此您发现的任何问题都不会得到修复:
- The future of binary embedding mozilla.dev.embedding 中的公告
- Ubuntu withdraws gtkmozembed
WebKitGTK经常用作替代浏览器组件(基于 WebKit),尽管我发现通过 NPAPI 运行 Adobe Flash 插件不稳定。如果您可以忍受它的局限性,gtkhtml 更简单,因此更可靠,并且可能更适合您。
最后,对于来到这里寻找 gtkmozembed 在 xulrunner 中使用 SIGSEGV 崩溃的解决方案的人(就像我一样),答案可能是您忘记通过 run-mozilla.sh
运行您的应用程序,这tells Mozilla where to find its components .
关于c++ - 带有 XULRunner 15 的 Linux 上的 XRE_InitEmbedding2 SIGSEGV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12059083/