當我從我的電腦以root身份運行時,我的C++程序給了我一個seg故障,但是當我啓動一個遠程會話時,卻沒有。我的程序僅作爲用戶從我的電腦運行。可能是什麼問題?我寫了一個嵌入式設備的程序,我用它來編譯:以root身份運行時出現分段錯誤?
gcc -Werror notify.cc -o notify `pkg-config --libs --cflags gtk+-2.0 hildon-notifymm hildonmm hildon-fmmm'
我沒有收到任何錯誤。這可能是一個國旗問題嗎?我可以發佈我的代碼。
編輯:當我開始我的程序使用gdb我得到這個:
Program received signal SIGSEGV, Segmentation fault.
0x40eed060 in strcmp() from /lib/libc.so.6
0x40eed060 <strcmp+0>: ldrb r2, [r0], #1
回溯給這個:
(gdb) backtrace
#0 0x40eed060 in strcmp() from /lib/libc.so.6
#1 0x40b7f190 in dbus_set_g_error()
from /usr/lib/libdbus-glib-1.so.2
#2 0x40b7d060 in dbus_g_bus_get() from /usr/lib/libdbus-glib-1.so.2
#3 0x400558ec in notify_init() from /usr/lib/libnotify.so.1
#4 0x4004a240 in Notify::init(Glib::ustring const&)()
from /usr/lib/libnotifymm-1.0.so.7
#5 0x40033794 in Hildon::notify_init(Glib::ustring const&)()
from /usr/lib/libhildon-notifymm-1.0.so.1
這裏是我的代碼:
#include <hildonmm.h>
#include <hildon-notifymm.h>
#include <hildon/hildon-notification.h>
#include <libnotifymm/init.h>
#include <gtkmm/stock.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <iostream>
int main(int argc, char *argv[])
{
// Initialize gtkmm and maemomm:
Hildon::init();
Hildon::notify_init("Notification Example");
// Initialize D-Bus (needed by hildon-notify):
DBusConnection* conn = dbus_bus_get(DBUS_BUS_SESSION, NULL);
dbus_connection_setup_with_g_main(conn, NULL);
// Create a new notification:
Glib::RefPtr<Hildon::Notification> notification = Hildon::Notification::create("Something Happened", "A thing has just happened.", Gtk::Stock::OPEN);
// Show the notification:
std::auto_ptr<Glib::Error> ex;
notification->show(ex);
if(ex.get())
{
std::cerr << "Notification::show() failed: " << ex->what() << std::endl;
}
return 0;
}
編輯:問題解決了。程序在終端的env中需要一個DBUS_SESSION_ADDRESS。