Building static libraries using VS2013 (VC12)

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
c-273
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 24, 2008 9:33 am

Building static libraries using VS2013 (VC12)

Post by c-273 » Sat Oct 04, 2014 4:36 pm

I just downloaded the latest 3.0.1 wxWidgets source code for Windows (31MB zip file) and to build the static libraries using VS2013 and the wx_vc12.sln VS2013 solution file and project files supplied in this zip file.

Unfortunately, ALL the static library builds (Debug & Release for platforms Win32 & x64) specify the incorrect Compiler "Code Generation" "Runtime Library" option i.e. /MD (Release builds) or /MDd (Debug builds) instead of /MT and /MTd respectively. Thus the main configuation says create a static library but the compiler builds the DLL version code.

This requires all the wx_vc12_*.vcxproj files to be corrected for the static build configurations for both platforms.

What concerns me is that the GitHub repository doesn't have the VC10, VC11 or VC12 project files in the build\msw directory, which are included in this zip file - it stops at VC9 and yet they are in the official download?

c-273
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 24, 2008 9:33 am

Re: Building static libraries using VS2013 (VC12)

Post by c-273 » Sat Oct 04, 2014 4:38 pm

Patch file attached
Attachments
static_build.zip
Patch file
(2.35 KiB) Downloaded 143 times

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

Re: Building static libraries using VS2013 (VC12)

Post by PB » Sat Oct 04, 2014 6:11 pm

AFAIK, even the static builds of wxWiddgets have always used to link to the dynamic version of MSVCRT by default, just as Microsoft recommends? (in the command line build this is controlled by the value of RUNTIME_LIBS).

Regarding the missing wx_vc12_*.vcxproj files, I can still see them in the 3.0 branch: https://github.com/wxWidgets/wxWidgets/ ... /build/msw.

They were removed from the trunk though in r77008:
https://github.com/wxWidgets/wxWidgets/ ... 5ed2ece66d

c-273
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 24, 2008 9:33 am

Re: Building static libraries using VS2013 (VC12)

Post by c-273 » Sat Oct 04, 2014 10:13 pm

I am afraid that the commit is wrong. The project files change between releases. For example, VS2013 changed the second line of every project file from:
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
to
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

Also, the each version has a different "Platform Toolset", e.g. VC10 is V100, VC11 is V110 and VC12 is V120. In addtion, if you wanted to support Windows XP (even if Microsoft doesn't), then one needs the Platform Toolsets V100_XP, V110_XP or V120_XP. If you open an earlier version, Visual Studio will want to upgrade the projects. If a user only has one version of Visual Studio then this probably would not be a problem but if the has 2 (like I have as I do the migration from VS2012 to VS2013), updating the project files to VS2013 will mean that they are no longer useable with VS2012.

I suggest that these solutions and project files need putting back.

As to specifying the Runtime Library as still being a DLL when trying to build the static library, all I can say it might build the libraries but the project trying to use them complains that they were built with the wrong configuration and will not link in the static libraries and so, of course, the project will not build. Can you supply the reference for what you say Microsoft recommends please?

For wxWidgets 2.8.12, I used the wxPack batch file (wxBuild_wxWidgets.bat) to build the static libraires (see https://github.com/rjpcomputing/wxpack/wiki) and it specifies "RUNTIME_LIBS=static" to its Makefile (if building the DLLs, the value is "RUNTIME_LIBS=dynamic"). I have just downloaded the latest version of this file and it supports VS2013 and uses the wxWidgets supplied config.vc and makefile.vc files. I have attached it. I may use it in future. PS. I don't use the rest of the files/products supplied with wxPack downloads.
Attachments
wxBuild_wxWidgets.txt
Batch file renamed to .txt for upload.
(18.97 KiB) Downloaded 113 times

c-273
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 24, 2008 9:33 am

Re: Building static libraries using VS2013 (VC12)

Post by c-273 » Sat Oct 04, 2014 10:43 pm

Actually, I just checked this batch file. It works fine for me without any VS2013 solution and project files AND it sets /MT & /MTd for static libraries, as it should. It supports VC7.1 and later as well as the gcc compiler that I don't currently use.

So, no need to restore the VC10, VC11 & VC12 solution and project files for me any more. Mind you they are still incorrect (as are probably the earlier project files still in the repository), IMHO, in that they do not set the correct Runtime Libraries for building the static libraries.

Thanks anyway

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

Re: Building static libraries using VS2013 (VC12)

Post by doublemax » Sat Oct 04, 2014 11:15 pm

"static" only means that the wxWidgets libraries are linked statically. The CRTs are always set for dynamic loading. This is intentional.
Use the source, Luke!

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

Re: Building static libraries using VS2013 (VC12)

Post by PB » Sun Oct 05, 2014 9:13 am

Let me conclude:

Official wxWidgets makefiles/projects have always (well at least for past five or so years I've been using them) linked to the dynamic versions of CRT. This is recommended so: (1) it is assured that all potential parts of the application (the .exe and various DLL it may use) use the same version of CRT, you can see why it may be important here; (2) so that Microsoft can release a new version of the CRT when an important bug or a security issue was found and all the applications linking to it dynamically can automatically benefit from the new version. I, for one, also used to prefer to link to the CRT statically, but I guess for better or worse, the days of self-contained applications are pretty much over.

Regarding wxPack, AFAIK this is a third part project and it overriding official wxWidgets settings is something one must account for.

Last but not least, if you think you found a bug/issue in wxWidgets, the best way to let the developers know is to submit a ticket on wxTrac. This is just a user forum.

c-273
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 24, 2008 9:33 am

Re: Building static libraries using VS2013 (VC12)

Post by c-273 » Sun Oct 05, 2014 9:25 am

I understand your answer but that only really applies if you wish to use DLLs for everything. We build self-contained applications not requiring the user to install Microsoft distributions and so we use static libraies for all and we release new (free) versions regularly should MIcrosoft or anyone else report a security issue. For that to work with wxWidgets builds, the compiler must know that we want static libraries and the runtime must be set to static (/MT & /MTd). The application will not link successfully without this.

Runtime needs to be /MD & /MDd to create DLLs not for static linked libraries.

I will continue to use this batch file, which is really only a wrapper to your supplied makefile. It is not as such a 3rd party product, although other items in it are but, as I said, I do not use them.

Thank you for your time.

PS. Let me know if you wish a list of all those link errors if the static libraries are built incorrectly.

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

Re: Building static libraries using VS2013 (VC12)

Post by PB » Sun Oct 05, 2014 9:38 am

Once again, wxWidgets do let you link to the CRT statically in the non-shared builds, just for the reasons described the default setting in the library and samples projects is different. I don't think they can change that easily even if they wanted to, as that would break all existing projects using wxWidgets in default configuration.

I am in no way affiliated with wxWidgets so if you believe something is wrong, you have to reach the developers, either via mailing lists or wxTrac.

c-273
Earned a small fee
Earned a small fee
Posts: 12
Joined: Thu Jan 24, 2008 9:33 am

Re: Building static libraries using VS2013 (VC12)

Post by c-273 » Sun Oct 05, 2014 7:14 pm

FYI - I attach the errors I get when I build the static libraries with /MD & /MDd instead of /MT and /MTd. There are 363 LNK2038 and 150 LNK2005 errors in the one Debug build of our application - 513 in total. All disappear when building the wxWidgets static libraries using /MT & /MTd switches.

This is purely informational as I will continue to use the batch file and the static switches.

Thank you for your contribution to the discussion.

PS. Just to show it is not just us, we also use the Xerces-C++ XML parser (http://xerces.apache.org/xerces-c/). The project files for this provide 3 sets of build environments -
Debug/Release - Configuration type - Dynamic Library (.dll), Runtime Library: /MD & /MDd
ICU Debug/ICU Release - Configuration type - Dynamic Library (.dll), Runtime Library: /MD & /MDd
Static Debug/Static Release - Configuration type - Static Library (.lib), Runtime Library: /MT & /MTd

From their web page: The ICU buld provides support for over 180 different encodings and/or locale specific message support. ICU stands for International Components for Unicode and is an open source distribution from IBM.
Attachments
Link errors.txt
Link Error list. 513 in total!
(82.86 KiB) Downloaded 67 times

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

Re: Building static libraries using VS2013 (VC12)

Post by doublemax » Sun Oct 05, 2014 9:35 pm

That doesn't really have anything to do with wxWidgets. Whichever CRT configuration you choose, it must be the same for all components in your project.

And if you need statically linked CRTs you can change the wxWidgets configuration accordingly.
Use the source, Luke!

orbitcowboy
I live to help wx-kind
I live to help wx-kind
Posts: 178
Joined: Mon Jul 23, 2007 9:01 am

Re: Building static libraries using VS2013 (VC12)

Post by orbitcowboy » Fri Nov 28, 2014 7:21 am

Since i had the same problem. I created a short tutorial on how to compile the wxWidgets library into a static lib with Visual C++ 2010.

https://sites.google.com/site/opensourc ... ic-library
OS: Ubuntu 9.04 (32/64-Bit), Debian Lenny (32-Bit)
Compiler: gcc/g++-4.3.3 , gcc/g++-4.4.0
wxWidgets: 2.8.10,2.9.0

Post Reply