Page 1 of 1

LNK2019 wxString::SubstrBufFromType

Posted: Mon Dec 02, 2019 2:56 am
by firescript
Hello :
I get the following error when compiling the simple example:

Code: Select all

error LNK2019: unresolved external symbol "private: static struct wxString::SubstrBufFromType<class wxScopedCharTypeBuffer<unsigned short> > __cdecl wxString::ConvertStr(char const *,unsigned __int64,class wxMBConv const &)" (?ConvertStr@wxString@@CA?AU?$SubstrBufFromType@V?$wxScopedCharTypeBuffer@G@@@1@PEBD_KAEBVwxMBConv@@@Z) referenced in function "private: static class wxScopedCharTypeBuffer<unsigned short> __cdecl wxString::ImplStr(char const *,class wxMBConv const &)" (?ImplStr@wxString@@CA?AV?$wxScopedCharTypeBuffer@G@@PEBDAEBVwxMBConv@@@Z)
fatal error LNK1120: 1 unresolved externals
Unicode version
lib files as followed:
wxbase31u.lib wxbase31u_net.lib wxbase31u_xml.lib wxexpat.lib wxjpeg.lib wxmsw31u_aui.lib wxmsw31u_core.lib wxmsw31u_gl.lib wxmsw31u_html.lib wxmsw31u_qa.lib wxmsw31u_ribbon.lib wxmsw31u_richtext.lib wxmsw31u_stc.lib wxmsw31u_webview.lib wxmsw31u_xrc.lib wxpng.lib wxregexu.lib winmm.lib wxscintilla.lib wxtiff.lib wxzlib.lib wxmsw31u_adv.lib wxmsw31u_media.lib wxmsw31u_propgrid.lib comctl32.lib rpcrt4.lib wsock32.lib odbc32.lib Ws2_32.lib urlmon.lib wininet.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

the simple example code:

Code: Select all

simple_window.h
#ifndef SIMPLE_WINDOW_H
#define SIMPLE_WINDOW_H

#define wxDEBUG_LEVEL 0

#include <wx/wx.h>

class myFrame : public wxFrame
{
public:
	myFrame(const wxString title);
private:
	void OnQuitButton(wxCommandEvent &event);
	wxDECLARE_EVENT_TABLE();
};

#endif

Code: Select all

simple_window.cpp
#include"simple_window.h"

#define ID_BUTTON_QUIT 40000

wxBEGIN_EVENT_TABLE(myFrame, wxFrame)
	EVT_BUTTON(ID_BUTTON_QUIT, myFrame::OnQuitButton)
wxEND_EVENT_TABLE()

myFrame::myFrame(const wxString title):wxFrame(NULL,wxID_ANY,title)
{
	SetWindowStyleFlag(wxFRAME_NO_TASKBAR | wxNO_BORDER);  
	wxButton* m_button1 = new wxButton(this, ID_BUTTON_QUIT, wxT("提示"), wxDefaultPosition, wxDefaultSize, 0);
}

void myFrame::OnQuitButton(wxCommandEvent &event)
{
	wxMessageBox(wxT("hoho"), wxT("Message"),wxYES|wxNO,this);
}
How to solve it? Thank you!

Re: LNK2019 wxString::SubstrBufFromType

Posted: Mon Dec 02, 2019 6:23 am
by doublemax
I don't get any error when compiling your code.

But try removing the "#define wxDEBUG_LEVEL 0" line. This can only be changed when compiling the wxWidgets libraries, you can't override this in user code.

If that doesn't work, make sure that your code is compiled with the same configuration that was used when building the wxWidgets libraries.

Re: LNK2019 wxString::SubstrBufFromType

Posted: Tue Dec 03, 2019 11:41 am
by stahta01
I thought wxDEBUG_LEVEL could be redefined in user code; can you confirm it can not be?

Tim S.

Re: LNK2019 wxString::SubstrBufFromType

Posted: Wed Dec 04, 2019 1:43 pm
by ONEEYEMAN
Hi,
User code should be compiled with exactly the same set of option s as the library.

Thank you.

Re: LNK2019 wxString::SubstrBufFromType

Posted: Wed Dec 04, 2019 2:13 pm
by PB
Actually, the docs clearly state that wxDEBUG_LEVEL can have different values in the user application and wxWidgets, as long as its value in the application is set before including any wxWidgets headers (which the OP does).

Re: LNK2019 wxString::SubstrBufFromType

Posted: Fri Dec 06, 2019 6:44 am
by firescript
doublemax wrote: Mon Dec 02, 2019 6:23 am I don't get any error when compiling your code.

But try removing the "#define wxDEBUG_LEVEL 0" line. This can only be changed when compiling the wxWidgets libraries, you can't override this in user code.

If that doesn't work, make sure that your code is compiled with the same configuration that was used when building the wxWidgets libraries.
If I remove #define wxDEBUG_LEVEL 0,will get another error:

Code: Select all

error LNK2019: unresolved external symbol "void __cdecl wxOnAssert(char const *,int,char const *,char const *,unsigned short const *)" (?wxOnAssert@@YAXPEBDH00PEBG@Z) referenced in function "protected: virtual class wxGDIRefData * __cdecl wxGDIImage::CloneGDIRefData(class wxGDIRefData const *)const " (?CloneGDIRefData@wxGDIImage@@MEBAPEAVwxGDIRefData@@PEBV2@@Z)

Re: LNK2019 wxString::SubstrBufFromType

Posted: Fri Dec 06, 2019 6:47 am
by firescript
ONEEYEMAN wrote: Wed Dec 04, 2019 1:43 pm Hi,
User code should be compiled with exactly the same set of option s as the library.

Thank you.
Can you list some settings? Because I am in another environment, not pure VS, and I am not familiar with some default settings of that environment. If you can list some settings that need attention, I can try to change them in the environment and see if they can be solved. Thank you very much!

library:Use Default Setting (Unicode and Static). VS2008

About another environment: setting in Imakefile.mk file
BUILT_OBJECT_TYPE=SHARED LIBRARY
LOCAL_LDFLAGS=/LIBPATH:"F:\XXXX\wxWidgets-3.1.3\lib\vc_x64_lib"
SYS_LIBS=wxbase31u.lib wxbase31u_net.lib XXXXXXXX .....
LOCAL_CCFLAGS=/I"F:\XXXX\wxWidgets-3.1.3\include" .......

Re: LNK2019 wxString::SubstrBufFromType

Posted: Fri Dec 06, 2019 3:40 pm
by ONEEYEMAN
Hi,
Only you know what options you used when you compiled wxWidgets.
Did you use static/dynamic one? UNICODE or not? multilib or not? debug vs release?
Those are major ones that absolutely has to match.

On top of that there are some that defined inside setup.h or configure that also should match to the T.
Otherwise you might get an unusual behavior.

Of course there are some default settings to compile the library and then you just need to know what they are to compile your own code. But that a different story.

On top of that - the library and the user code needs the same compiler (or better put ABI-compatible compiler).
However it looks like you are not using MSVC at all when compiling your own code.Am I right?

Thank you.

Re: LNK2019 wxString::SubstrBufFromType

Posted: Fri Dec 06, 2019 4:48 pm
by doublemax
Please start from scratch by building the "minimal" sample that comes with wxWidgets. That should still work out of the box with the provided project files, even with your old VS version.