C++ wxWidgets程序段故障

C++ wxWidgets程序段故障,c++,macos,segmentation-fault,wxwidgets,C++,Macos,Segmentation Fault,Wxwidgets,我刚刚在OSX(10.11.3(15D21))上使用wxWidgets启动了一个irc客户端项目 然而,当我编译代码并运行它时,由于某种原因,它会出现故障。我用gdb运行了这个程序,得到了下面的输出 Program received signal SIGSEGV, Segmentation fault. 0x00007fff9793871a in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocat

我刚刚在OSX(10.11.3(15D21))上使用wxWidgets启动了一个irc客户端项目

然而,当我编译代码并运行它时,由于某种原因,它会出现故障。我用gdb运行了这个程序,得到了下面的输出

Program received signal SIGSEGV, Segmentation fault.
0x00007fff9793871a in std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::assign(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) () from /usr/lib/libstdc++.6.dylib
main.cpp

#include "main.hpp"

wxIMPLEMENT_APP(IrcClientApp);

bool IrcClientApp::OnInit() {
    IrcClientFrame* frame = new IrcClientFrame("IRC client", wxPoint(100, 100), wxSize(600, 400));
    frame->Show(true);
    return true;
}
frame.hpp

#ifndef __frame_hpp
#define __frame_hpp

class IrcClientFrame : public wxFrame {
private:
    void about(wxCommandEvent&);
    void exit(wxCommandEvent&);

    wxDECLARE_EVENT_TABLE();

public:
    IrcClientFrame(const wxString&, const wxPoint&, const wxSize&);
};

#endif
frame.cpp

#include "main.hpp"

wxBEGIN_EVENT_TABLE(IrcClientFrame, wxFrame)
    EVT_MENU(wxID_ABOUT, IrcClientFrame::about)
wxEND_EVENT_TABLE()

IrcClientFrame::IrcClientFrame(const wxString& title, const wxPoint& pos, const wxSize& size) :
    wxFrame(NULL, wxID_ANY, title, pos, size) {

    // About menu item
    wxMenu* menu_about = new wxMenu;
    menu_about->Append(wxID_ABOUT);

    // Menu bar
    wxMenuBar* menu_bar = new wxMenuBar;
    menu_bar->Append(menu_about, "&Help");

    // Set it
    SetMenuBar(menu_bar);

    CreateStatusBar();
    SetStatusText("This is the status text!");
}

void IrcClientFrame::about(wxCommandEvent& e) {
    wxMessageBox("Hello world", "Hello world", wxOK | wxICON_INFORMATION);
}

void IrcClientFrame::exit(wxCommandEvent& e) {
    Close(true);
}
使用以下Makefile编译

CC=g++
WXCONFIG=$(shell ../../../deps/bin/wx-config --cxxflags --libs)
INCLUDES=-I../../../src
CFLAGS=-g -std=c++11 -Wall -Wno-inconsistent-missing-override $(INCLUDES)
LDFLAGS=-L../../../deps/lib
BIN=../bin/client
CPPS=main.cpp frame.cpp

all: mkdir_bin examples

examples: $(CPPS)
    $(CC) $(CFLAGS) $(WXCONFIG) $(CPPS) -o $(BIN)

mkdir_bin: ; if [ ! -d ../bin ]; then mkdir ../bin; fi
clean:     ; if [   -d ../bin ]; then rm -rf ../bin; fi
这是事故报告中的调度队列

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x1:
--> 
    __TEXT                 0000000103d8d000-0000000103d93000 [   24K] r-x/rwx SM=COW  /Users/USER/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libstdc++.6.dylib               0x00007fff9793871a std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::assign(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) + 26
1   libwx_osx_cocoau_core-3.1.dylib 0x00000001041bcfbf wxNonOwnedWindow::Create(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&) + 63
2   libwx_osx_cocoau_core-3.1.dylib 0x00000001041c1311 wxTopLevelWindowMac::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 49
3   client                          0x0000000103d912ec wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 140 (frame.h:35)
4   client                          0x0000000103d90d2f IrcClientFrame::IrcClientFrame(wxString const&, wxPoint const&, wxSize const&) + 175 (frame.cpp:8)
5   client                          0x0000000103d9111d IrcClientFrame::IrcClientFrame(wxString const&, wxPoint const&, wxSize const&) + 45 (frame.cpp:23)
6   client                          0x0000000103d8e9b6 IrcClientApp::OnInit() + 134 (main.cpp:6)
7   libwx_osx_cocoau_core-3.1.dylib 0x00000001041b755e wxApp::CallOnInit() + 158
8   libwx_baseu-3.1.dylib           0x00000001048623f9 wxEntry(int&, wchar_t**) + 121
9   client                          0x0000000103d8e8a6 main + 38 (main.cpp:3)
10  libdyld.dylib                   0x00007fff9740a5ad start + 1
异常类型:EXC\u坏访问(SIGSEGV)
异常代码:0x0000000000000001处的内核地址无效
例外说明:EXC_尸体通知
0x1附近的VM区域:
--> 
__文本0000000 103D8D000-0000000 103D93000[24K]r-x/rwx SM=COW/Users/USER/*
线程0崩溃::调度队列:com.apple.main-Thread
0 libstdc++.6.dylib 0x00007fff9793871a std::basic_string::assign(std::basic_string const&)+26
1 libwx_osx_cocoau_core-3.1.dylib 0x00000001041bcfbf wxNownedWindow::Create(wxWindow*,int,wxPoint const&,wxSize const&,long,wxString const&)+63
2 libwx_osx_cocoau_core-3.1.dylib 0x00000001041c1311 wxTopLevelWindowMac::Create(wxWindow*,int,wxString const&,wxPoint const&,wxSize const&,long,wxString const&)+49
3客户端0x0000000103d912ec wxFrame::wxFrame(wxWindow*,int,wxString常量&,wxPoint常量&,wxSize常量&,long,wxString常量&)+140(frame.h:35)
4客户端0x0000000103d90d2f IrcClientFrame::IrcClientFrame(wxString常量&,wxPoint常量&,wxSize常量&)+175(frame.cpp:8)
5客户端0x0000000103d9111d IrcClientFrame::IrcClientFrame(wxString常量&,wxPoint常量&,wxSize常量&)+45(frame.cpp:23)
6客户端0x0000000103d8e9b6 IrcClientApp::OnInit()+134(main.cpp:6)
7 libwx_osx_cocoau_core-3.1.dylib 0x00000001041b755e wxApp::CallOnInit()+158
8 libwx_baseu-3.1.dylib 0x00000001048623f9 wxEntry(int和,wchar\u t**)+121
9客户端0x0000000103d8e8a6主+38(主cpp:3)
10 libdyld.dylib 0x00007fff9740a5ad开始+1

您没有使用
-std=c++11
构建库,但正在将其用于您自己的代码,这可能就是问题所在。OS X下推荐的方法是使用
-std=c++11-stdlib=libc++
编译库和您自己的代码,即删除旧的生成目录(您确实在单独的目录中生成了,不是吗?),然后重新运行configure with
cxflags=“-std=c++11-stdlib=libc++”
。最后,将您自己的makefile更新为使用
-stdlib=libc++

您是如何编译的?您好@MarkSetchell,请参阅我的编辑,我已经添加了我用来编译的makefile文件。您是否安装了带有
自制
的wxWidgets?我编译了它并将其前缀添加到“../../../deps”目录中。我还应该注意到这是今天的版本,所以它是最新的稳定版本。@Dillan,你的配置行是什么?你是用Xcode编译的还是从终端编译的?
Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000001
Exception Note:        EXC_CORPSE_NOTIFY

VM Regions Near 0x1:
--> 
    __TEXT                 0000000103d8d000-0000000103d93000 [   24K] r-x/rwx SM=COW  /Users/USER/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libstdc++.6.dylib               0x00007fff9793871a std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::assign(std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> > const&) + 26
1   libwx_osx_cocoau_core-3.1.dylib 0x00000001041bcfbf wxNonOwnedWindow::Create(wxWindow*, int, wxPoint const&, wxSize const&, long, wxString const&) + 63
2   libwx_osx_cocoau_core-3.1.dylib 0x00000001041c1311 wxTopLevelWindowMac::Create(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 49
3   client                          0x0000000103d912ec wxFrame::wxFrame(wxWindow*, int, wxString const&, wxPoint const&, wxSize const&, long, wxString const&) + 140 (frame.h:35)
4   client                          0x0000000103d90d2f IrcClientFrame::IrcClientFrame(wxString const&, wxPoint const&, wxSize const&) + 175 (frame.cpp:8)
5   client                          0x0000000103d9111d IrcClientFrame::IrcClientFrame(wxString const&, wxPoint const&, wxSize const&) + 45 (frame.cpp:23)
6   client                          0x0000000103d8e9b6 IrcClientApp::OnInit() + 134 (main.cpp:6)
7   libwx_osx_cocoau_core-3.1.dylib 0x00000001041b755e wxApp::CallOnInit() + 158
8   libwx_baseu-3.1.dylib           0x00000001048623f9 wxEntry(int&, wchar_t**) + 121
9   client                          0x0000000103d8e8a6 main + 38 (main.cpp:3)
10  libdyld.dylib                   0x00007fff9740a5ad start + 1