Visual Studio 2019 issue with static linking Topic is solved

Do you have a question about makefiles, a compiler or IDE you are using and need to know how to set it up for wxWidgets or why it doesn't compile but other IDE's do ? Post your questions here.
Post Reply
jdratlif1261
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Sep 03, 2019 12:15 am

Visual Studio 2019 issue with static linking

Post by jdratlif1261 » Tue Sep 03, 2019 12:35 am

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 [email protected]	dwsrame	C:\Users\john\Desktop\build\dwsrame\vstudio\wxmsw30u_core.lib(ownerdrw.obj)	1	
Error	LNK2019	unresolved external symbol [email protected] referenced in function "public: virtual bool __thiscall wxApp::Initialize(int &,wchar_t * *)" ([email protected]@@[email protected])	dwsrame	C:\Users\john\Desktop\build\dwsrame\vstudio\wxmsw30u_core.lib(app.obj)	1	
Error	LNK2019	unresolved external symbol [email protected] referenced in function "public: bool __thiscall wxSpinButton::Create(class wxWindow *,int,class wxPoint const &,class wxSize const &,long,class wxString const &)" ([email protected]@@[email protected]@[email protected]@[email protected]@[email protected]@@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.

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Visual Studio 2019 issue with static linking

Post by PB » Tue Sep 03, 2019 5:23 am

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).

jdratlif1261
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Sep 03, 2019 12:15 am

Re: Visual Studio 2019 issue with static linking

Post by jdratlif1261 » Tue Sep 03, 2019 4:02 pm

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 [email protected] referenced in function "public: bool __thiscall Uuid::Set(wchar_t const *)" ([email protected]@@[email protected])	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.

User avatar
doublemax
Moderator
Moderator
Posts: 13985
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Visual Studio 2019 issue with static linking

Post by doublemax » Tue Sep 03, 2019 4:12 pm

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.
Use the source, Luke!

PB
Part Of The Furniture
Part Of The Furniture
Posts: 2020
Joined: Sun Jan 03, 2010 5:45 pm

Re: Visual Studio 2019 issue with static linking

Post by PB » Tue Sep 03, 2019 4:55 pm

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 pm
There 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>"...

jdratlif1261
In need of some credit
In need of some credit
Posts: 4
Joined: Tue Sep 03, 2019 12:15 am

Re: Visual Studio 2019 issue with static linking

Post by jdratlif1261 » Tue Sep 03, 2019 10:59 pm

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.

Post Reply