2009-09-11 89 views
2

当编译我的wxWidget HelloWorld应用程序,我收到以下错误:C++:wxWidget的HelloWorld

Warning 1 warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library wxWidget__HelloWorld wxWidget__HelloWorld 
Error 2 error LNK2001: unresolved external symbol "public: virtual bool __thiscall wxApp::Initialize(int &,wchar_t * *)" ([email protected]@@[email protected]) minimal.obj wxWidget__HelloWorld 
Error 3 error LNK2001: unresolved external symbol "public: virtual void __thiscall wxAppConsole::OnAssertFailure(wchar_t const *,int,wchar_t const *,wchar_t const *,wchar_t const *)" ([email protected]@@[email protected]) minimal.obj wxWidget__HelloWorld 
Error 4 error LNK2001: unresolved external symbol "public: virtual void __thiscall wxAppConsole::OnAssert(wchar_t const *,int,wchar_t const *,wchar_t const *)" ([email protected]@@[email protected]) minimal.obj wxWidget__HelloWorld 
Error 5 error LNK2019: unresolved external symbol "protected: void __thiscall wxStringBase::InitWith(wchar_t const *,unsigned int,unsigned int)" ([email protected]@@[email protected]) referenced in function "public: __thiscall wxStringBase::wxStringBase(wchar_t const *)" ([email protected]@[email protected][email protected]) minimal.obj wxWidget__HelloWorld 
Error 6 error LNK2019: unresolved external symbol "public: int __cdecl wxString::Printf(wchar_t const *,...)" ([email protected]@@QAAHPB_WZZ) referenced in function "public: void __thiscall MyFrame::OnAbout(class wxCommandEvent &)" ([email protected]@@[email protected]@@Z) minimal.obj wxWidget__HelloWorld 
Error 7 error LNK2001: unresolved external symbol "wchar_t const * const wxEmptyString" ([email protected]@3PB_WB) minimal.obj wxWidget__HelloWorld 
Error 8 error LNK2001: unresolved external symbol "wchar_t const * const wxStatusLineNameStr" ([email protected]@3QB_WB) minimal.obj wxWidget__HelloWorld 
Error 9 error LNK2001: unresolved external symbol "wchar_t const * const wxFrameNameStr" ([email protected]@3QB_WB) minimal.obj wxWidget__HelloWorld 
Error 10 error LNK2019: unresolved external symbol "void __cdecl wxOnAssert(wchar_t const *,int,char const *,wchar_t const *,wchar_t const *)" ([email protected]@[email protected]) referenced in function "public: __thiscall wxStringBase::wxStringBase(class wxStringBase const &)" ([email protected]@[email protected]@@Z) minimal.obj wxWidget__HelloWorld 
Error 11 fatal error LNK1120: 9 unresolved externals F:\C++\_2008_\wxWidget__HelloWorld\Debug\wxWidget__HelloWorld.exe wxWidget__HelloWorld 

我的源代码如下:

//

Name:  minimal.cpp 
// Purpose:  Minimal wxWidgets sample 
// Author:  Julian Smart 

#include "wx/wx.h" 

// Declare the application class 
class MyApp : public wxApp 
{ 
public: 
    // Called on application startup 
    virtual bool OnInit(); 
}; 

// Declare our main frame class 
class MyFrame : public wxFrame 
{ 
public: 
    // Constructor 
    MyFrame(const wxString& title); 

    // Event handlers 
    void OnQuit(wxCommandEvent& event); 
    void OnAbout(wxCommandEvent& event); 

private: 
    // This class handles events 
    DECLARE_EVENT_TABLE() 
}; 

// Implements MyApp& GetApp() 
DECLARE_APP(MyApp) 

// Give wxWidgets the means to create a MyApp object 
IMPLEMENT_APP(MyApp) 

// Initialize the application 
bool MyApp::OnInit() 
{ 
    // Create the main application window 
    MyFrame *frame = new MyFrame(wxT("Minimal wxWidgets App")); 

    // Show it 
    frame->Show(true); 

    // Start the event loop 
    return true; 
} 

// Event table for MyFrame 
BEGIN_EVENT_TABLE(MyFrame, wxFrame) 
    EVT_MENU(wxID_ABOUT, MyFrame::OnAbout) 
    EVT_MENU(wxID_EXIT, MyFrame::OnQuit) 
END_EVENT_TABLE() 

void MyFrame::OnAbout(wxCommandEvent& event) 
{ 
    wxString msg; 
    msg.Printf(wxT("Hello and welcome to %s"), 
       wxVERSION_STRING); 


    wxMessageBox(msg, wxT("About Minimal"), 
       wxOK | wxICON_INFORMATION, this); 
} 

void MyFrame::OnQuit(wxCommandEvent& event) 
{ 
    // Destroy the frame 
    Close(); 
} 

#include "mondrian.xpm" 

MyFrame::MyFrame(const wxString& title) 
     : wxFrame(NULL, wxID_ANY, title) 
{ 
    // Set the frame icon 
    SetIcon(wxIcon(mondrian_xpm)); 

    // Create a menu bar 
    wxMenu *fileMenu = new wxMenu; 

    // The "About" item should be in the help menu 
    wxMenu *helpMenu = new wxMenu; 
    helpMenu->Append(wxID_ABOUT, wxT("&About...\tF1"), 
        wxT("Show about dialog")); 

    fileMenu->Append(wxID_EXIT, wxT("E&xit\tAlt-X"), 
        wxT("Quit this program")); 

    // Now append the freshly created menu to the menu bar... 
    wxMenuBar *menuBar = new wxMenuBar(); 
    menuBar->Append(fileMenu, wxT("&File")); 
    menuBar->Append(helpMenu, wxT("&Help")); 

    // ... and attach this menu bar to the frame 
    SetMenuBar(menuBar); 

    // Create a status bar just for fun 
    CreateStatusBar(2); 
    SetStatusText(wxT("Welcome to wxWidgets!")); 
} 

是什么失踪?

+0

你正在链接正确的库吗? – kibibu 2009-09-11 04:56:21

+0

我已经链接了一些。但无法理解哪些是缺失的。 – anonymous 2009-09-11 05:01:10

+0

我有 - wxmsw28d_core.lib wxbase28d.lib wxtiffd.lib wxjpegd.lib wxpngd.lib wxzlibd.lib wxregexd.lib wxexpatd.lib WINMM.LIB comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib – anonymous 2009-09-11 05:02:14

回答

3

确保你的项目上的设置与你所有的依赖关系正在使用的(实际上你应该匹配依赖项:))。

设置,可能会导致连接问题与MS工具链(除了明显不链接库在所有):

  • 使用Unicode /多字节字符集
  • 视wchar_t的内置型。

当你知道那该死的未解决,为wchar_t *含符号是在你刚挂入该死库中,这可能是这两个中的一个。

  • 运行时(多/单线程[debug] [dll])。

这是您的LIBCMTD警告的原因。对于像__free或malloc或其他标准外观的缺失/冲突符号。而且,对于神秘而言,如果你以某种方式设法将2个不同的运行时间链接成一个二进制文件(我已经看到它!),那么在跨越dll边界时甚至是空的地方都不会崩溃。像_LIB,_DLL,QT_DLL等

那些由一些库用于

  • 可疑预处理器定义以决定是否应该代码被静态或动态链接。它们通常会影响伴随lib或dll的标头。你必须知道你是否需要他们。 RTFM或查看配置的工作示例项目。

    因此,对于你的问题,首先确保你添加了你必须的任何wxWidget库(以及他们需要的任何依赖)。搜索任何缺失的符号,并让谷歌指导你。有人会有同样的问题,并会在发现它之前将它发布到某个地方。

    一个很好的搜索词是需要对运行

    virtual bool __thiscall wxApp::Initialize 
    

    特殊照顾。当你得到所有你需要的库时,你会得到libcmt *或msvc *警告或冲突,然后检查你所有的项目设置,并检查我列出的4个项目是否正确和一致。如果你自己没有构建它们,你也必须了解它们的依赖关系。使用链接程序冗长标志也能确切地看到谁引入了不需要的运行时。

    其他编译器和链接器设置也可能会影响事物,所以请仔细阅读它们。

    大部分这些更改都需要重新编译。

    这是构建C++代码的乐趣。

2

在我看来,当您将错误的C运行时库链接到您时会收到错误信息。当您构建wxWidgets时,默认情况下,它分别使用多线程DLL选项和多线程调试DLL选项。

要在你应用程式,你需要去改变这一点:

建设 - >属性 - > C/C++ - >代码生成,然后改变其运行时库选项,并重新您的应用程序。

如果您希望对静态C运行时库链接,所以你不需要DLL,你可以运行一个发现再次替换所有的vcproj文件中wxWighets \建立\垃圾,更换

运行时库= “3”与运行时库=“1” 和

运行时库=“2”运行时库=“0”

这将改变DLL构建以及然而,这可能不是你想要的。