Page 1 of 1

Visual Studio 2019 issue with static linking

Posted: Tue Sep 03, 2019 12:35 am
by jdratlif1261
I'm trying to build my project with Visual Studio 2019 and the static wxWidgets libraries, but I keep running into linker errors. I have no problems building the project with the DLL libraries, only the static ones.

What I did:

Create new Project in VS by importing from existing code. I add my source directory. I make no other changes here.
I add the following paths to my Additional Includes in C/C++ project settings and Resource compiler settings (Release)

Code: Select all

..\source;C:\wxWidgets-3.0.4\lib\vc_lib\mswu;C:\wxWidgets-3.0.4\include;C:\wxWidgets-3.0.4\include\msvc
I added C:\wxWidgets-3.0.4\lib\vc_lib to my additional linker directories.
I added all the .lib files I could fine in the vc_lib directory.

Code: Select all

wxbase30u.lib
wxbase30u_net.lib
wxbase30u_xml.lib
wxexpat.lib
wxjpeg.lib
wxmsw30u_adv.lib
wxmsw30u_aui.lib
wxmsw30u_core.lib
wxmsw30u_gl.lib
wxmsw30u_html.lib
wxmsw30u_media.lib
wxmsw30u_propgrid.lib
wxmsw30u_qa.lib
wxmsw30u_ribbon.lib
wxmsw30u_richtext.lib
wxmsw30u_stc.lib
wxmsw30u_webview.lib
wxmsw30u_xrc.lib
wxpng.lib
wxregexu.lib
wxscintilla.lib
wxtiff.lib
wxzlib.lib
I do NOT have WXUSINGDLL defined in the PREPROCESSOR settings.

All the unresolved symbols reference wxmsw30u_core.lib.

Code: Select all

Error	LNK2001	unresolved external symbol __imp__ImageList_Create@20	dwsrame	C:\Users\john\Desktop\build\dwsrame\vstudio\wxmsw30u_core.lib(ownerdrw.obj)	1	
Error	LNK2019	unresolved external symbol __imp__InitCommonControls@0 referenced in function "public: virtual bool __thiscall wxApp::Initialize(int &,wchar_t * *)" (?Initialize@wxApp@@UAE_NAAHPAPA_W@Z)	dwsrame	C:\Users\john\Desktop\build\dwsrame\vstudio\wxmsw30u_core.lib(app.obj)	1	
Error	LNK2019	unresolved external symbol __imp__CreateUpDownControl@48 referenced in function "public: bool __thiscall wxSpinButton::Create(class wxWindow *,int,class wxPoint const &,class wxSize const &,long,class wxString const &)" (?Create@wxSpinButton@@QAE_NPAVwxWindow@@HABVwxPoint@@ABVwxSize@@JABVwxString@@@Z)	dwsrame	C:\Users\john\Desktop\build\dwsrame\vstudio\wxmsw30u_core.lib(msw_spinbutt.obj)	1	
Is there a step I'm missing?

If I change the vc_lib to vc_dll, and set the WXUSINGDLL PP directive, I can get it to link against the DLL library. I'm not sure what the difference is between static and DLL is here.

I tried comparing one of the sample programs vcprojx file, but I don't see any differences other than the sample uses relative paths.

Thanks.

Re: Visual Studio 2019 issue with static linking

Posted: Tue Sep 03, 2019 5:23 am
by PB
You seem to be missing Windows import library comctl32.lib from the list provided to the linker.

BTW, this

Code: Select all

..\source;C:\wxWidgets-3.0.4\lib\vc_lib\mswu;C:\wxWidgets-3.0.4\include;C:\wxWidgets-3.0.4\include\msvc
could be changed to this (notice that wxWidgets msvc-specific include precedes generic wxWidgets include and the build specific one is gone)

Code: Select all

..\source;C:\wxWidgets-3.0.4\include\msvc;C:\wxWidgets-3.0.4\include
and then you do not need to add any libraries by hand, wxWidgets will link them automagically (assuming your defines are correct).

Re: Visual Studio 2019 issue with static linking

Posted: Tue Sep 03, 2019 4:02 pm
by jdratlif1261
That got me closer, but not all the way there. I was left with 4 linker errors that said something about uuid.

Code: Select all

Error	LNK2019	unresolved external symbol __imp__UuidFromStringW@8 referenced in function "public: bool __thiscall Uuid::Set(wchar_t const *)" (?Set@Uuid@@QAE_NPB_W@Z)	dwsrame	C:\Users\john\Desktop\build\dwsrame\vstudio\wxmsw30u_core.lib(uuid.obj)	1	
I don't know what you mean by "assuming your defines are correct". I'm going to guess that they are not since changing the path as you suggested results in it saying it cannot find ../../../lib/vc_lib/msw/wx/setup.h.

Code: Select all

Error	C1083	 Cannot open include file: '../../../lib/vc_lib/msw/wx/setup.h': No such file or directory	dwsrame	C:\wxWidgets-3.0.4\include\msvc\wx\setup.h	121	
There are many guides on VC++ with wxWidgets, but they all seem to be quite outdated. All I could find about the defines is you could add some that would make it ignore certain libraries you don't have. But I built all of wx, so I don't see how that would help.

Here are all of the msw libraries that I have in my additional dependencies path.

Code: Select all

comctl32.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
I do see uuid.lib in there.

If I do not have the wx libraries added, I have many more LINK errors. So I must be doing something wrong with the automatic linking.

P.S. If it is relevant, this is a project I made MANY years ago (circa 2006). It was originally written with wx 2.6, and I updated it to work with 2.8 later. Everything compiles in 3.0 without changes.

Thanks.

Re: Visual Studio 2019 issue with static linking

Posted: Tue Sep 03, 2019 4:12 pm
by doublemax
That got me closer, but not all the way there. I was left with 4 linker errors that said something about uuid.
That should be in Rpcrt4.lib

If a missing reference is not a wxWidgets class, just Google for "msdn + missing reference", in this case "msdn uuid" and you will find the library that's missing.

Re: Visual Studio 2019 issue with static linking

Posted: Tue Sep 03, 2019 4:55 pm
by PB
jdratlif1261 wrote: Tue Sep 03, 2019 4:02 pm I don't know what you mean by "assuming your defines are correct".
I meant that in regard with using "automagical" wxWidgets library linking by listing MSVC-specific include first as I suggested. For example, you have define "_DEBUG" to have debug configuration linked or "WXUSINGDLL" when you want to use the DLL build. wxWidgets will then link all needed wxWidgets and Windows libraries properly, without you having to provide their list to the linker.
jdratlif1261 wrote: Tue Sep 03, 2019 4:02 pmThere are many guides on VC++ with wxWidgets, but they all seem to be quite outdated.
I always recommend using the official documentation shipped with wxWidgets, in your WXWIN/docs/msw/install.txt for v3.0. However, 3.0x is quite old and the docs have improved since, you can check it out online.

Anyway, the errors are not wxWidgets related, those are regular MS Windows libraries and as doublemax said, one can usually google those issues in a matter of seconds, using something like "unresolved external symbol <symbol name here>"...

Re: Visual Studio 2019 issue with static linking

Posted: Tue Sep 03, 2019 10:59 pm
by jdratlif1261
Thanks for all your help. I finally have it working.

The missing piece was to include MSVC first AND define _UNICODE in the PREPROCESSOR directives.

Now I don't have to define ANY additional libraries in the linker, MSVC or wxWidgets.