compiling project with /MT key - weird references to _wx_png and other upon linking

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
somename
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Jan 28, 2019 10:20 am

compiling project with /MT key - weird references to _wx_png and other upon linking

Post by somename »

Hello. I am using MS Visual Studio 2017, CMake for building wxWidgets from source and for making project using it. I am building a fully static wxWidgets aimed to compile inside a project with /MT or /MTd key. Here is my CMAKE setup:
2019-01-28 12_25_37-Window.png
2019-01-28 12_25_37-Window.png (15.11 KiB) Viewed 1526 times
The first thing is: when I compile BUILD_ALL project, I have to set up /MT key for wxexpat, wxjpeg, wxpng and wxregex projects, because compiling halts and I cannot get the wxbase lib file. But setting keys gets things done, wxWidgets compiles without errors and warnings.

Problems start when I try to compile project . I add wxmsw31u_core.lib;wxbase31u.lib lib files, as mentioned in tutorial, but I get then the following errors upon linking:
(one of them is Error LNK2001 unresolved external symbol _wx_png_create_info_struct wxmsw31u_core.lib(imagpng.obj) )
2019-01-28 12_37_27-Window.png
Another one is

Severity Code Description Project File Line Suppression State
Error LNK2001 unresolved external symbol __imp__CreateUpDownControl@48 ProjectSendSignal C:\SOME_NAME\OTHERCODE\SendSignal\SendSignal\ProjectSendSignal\wxmsw31u_core.lib(spinbutt.obj) 1
2019-01-28 12_37_59-Window.png
2019-01-28 12_37_59-Window.png (67.56 KiB) Viewed 1526 times
How do I make it compile? This project compiled with wxWidgets 3.0.1 /MD
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: compiling project with /MT key - weird references to _wx_png and other upon linking

Post by PB »

I can confirm the issue. The 3rd party libraries which are GIT submodules do not have the Runtime library set to static when wxBUILD_USE_STATIC_RUNTIME is checked. I believe it is a bug and you should report it on wxTrac (or fix it and provide a PR).

As for the linker errors, assuming there is no CRT mismatch, it looks as if the libraries (wxpng, comctl32, rpcrt4) were not added to linker in your project?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: compiling project with /MT key - weird references to _wx_png and other upon linking

Post by ONEEYEMAN »

Hi,
Is it an "experimental CMake" problem?
Can you build the libraries with the official wx solution out of the box?

Thank you.
somename
In need of some credit
In need of some credit
Posts: 2
Joined: Mon Jan 28, 2019 10:20 am

Re: compiling project with /MT key - weird references to _wx_png and other upon linking

Post by somename »

I have managed to compile my wxWidgets project. It is important that compiling of wxWidgets compiles fine, without errors. So all libraries (.lib) are built. My setup of lib files is the following:

wxmsw31ud_core.lib
wxbase31ud.lib
wxpngd.lib
wxzlibd.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
comctl32.lib
rpcrt4.lib


It works but is wrong that core libraries depend on png ( and zlib is required by png) library. My program does not use png explicitly.
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: compiling project with /MT key - weird references to _wx_png and other upon linking

Post by PB »

By the way, if you are using MSVC, adding libraries by hand is not necessary. It may be better to rely on wxWidgets autolinking feature available for MSVC, either by prepending $(WXWIN)\include\msvc to the compiler include paths or using a provided MSVS property sheet. And there's also VCPKG...

I will submit a ticket regarding the CRT linkage. I am not sure about the libpng dependency, will look into it. But I think it comes from the ability of wxBitmap and wxImage to use the format. However, if this were the case, why is not libtiff needed as well?
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: compiling project with /MT key - weird references to _wx_png and other upon linking

Post by PB »

The static CRT linking issue has actually already been fixed in the master
https://github.com/wxWidgets/wxWidgets/ ... 0a0da7bbbd
Post Reply