Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v141 static 3p library using CRT DLL #1745

Closed
VikingExplorer opened this issue Aug 31, 2017 · 10 comments
Closed

v141 static 3p library using CRT DLL #1745

VikingExplorer opened this issue Aug 31, 2017 · 10 comments
Labels
requires:repro The issue is not currently repro-able

Comments

@VikingExplorer
Copy link

VikingExplorer commented Aug 31, 2017

The biggest and most important use case for DLLs is for common code that changes rarely and is almost always backwardly compatible. In short, that's absolutely the windows API. That's why the CRT DLL should always be linked. I don't think it makes any sense to increase the size of one's own binaries by statically linking CRT.

However, it's quite a different story for our own modules/libraries and third party libraries we may use. To make these into DLLs implies that multiple EXEs will take advantage of shared DLLs to save RAM while being used by the customer.

A) customer using multiple EXEs from the same vendor is an edge case.
B) RAM is so plentiful, it's hardly worth the effort to use a DLL
C) DLLs introduces a significant deployment nightmare, otherwise known as DLL Hell.
D) using static libs excludes all unused/dead code from binaries, where DLLs include it all.

Given these two points, I naturally assumed that static 3p libraries linking to CRT DLL would be the default.

So, I'm surprised that the two triplets provided are:

DLL - CRT.DLL
Static - CRT-static

Neither of which seem particularly useful. Any help would be greatly appreciated.

@VikingExplorer
Copy link
Author

VikingExplorer commented Aug 31, 2017

I want to run vcpkg install again, but only after I figure out to make sure it correctly sets vc141.

Can someone please tell me how to:

a) control the tool chain to be 141
b) control CRT linkage to make sure it's dynamic

@VikingExplorer
Copy link
Author

In the triplets folder, I created: x64-windows-static-md.cmake

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_PLATFORM_TOOLSET v141)

In a VS2017 Cmd Prompt: vcpkg install cpprestsdk:x64-windows-static-md

In the folder: vcpkg\installed\x64-windows-static-md\debug\lib

Files:
boost_atomic-vc140-mt-gd-1_65.lib
boost_chrono-vc140-mt-gd-1_65.lib

As you can see, they are neither 141, nor are they md.

@VikingExplorer VikingExplorer changed the title BOOST_LIB_TOOLSET mismatch v141 static 3p library using CRT DLL Sep 2, 2017
@VikingExplorer
Copy link
Author

To restore #pragma linking, bugs must be fixed in vcpkg to create the properly named lib files.

Tried changing this to 141:
set(Boost_COMPILER "-vc140")
vcpkg\scripts\buildsystems\vcpkg.cmake line 74

However, this resulted in: Vcpkg version: 0.0.84-unknownhash

Someone please fix this ASAP.

@muemart
Copy link
Contributor

muemart commented Sep 4, 2017

Your triplet is correct and works fine, I just tried it myself.
The filenames are wrong, but the libs are built with VS2017 and linked to the dynamic CRT (you can verify it yourself by using dumpbin: dumpbin /directives [lib file])

@VikingExplorer
Copy link
Author

Yes, my triplet is fine, but vcpkg software has a bug. It mislabels the resulting lib files. What would be the point of Boost having a naming scheme if vcpkg is going to ignore it? Either vcpkg has a bug or they are being deliberately deceptive about it.

@ras0219-msft
Copy link
Contributor

ras0219-msft commented Sep 6, 2017

There's a longer discussion in #1338 (comment), however the crux of the issue is that all of the features provided by Boost's library name are already present in Vcpkg's buildsystem integration (including autolinking, in MSBuild).

We've tried pretty much every alternative (including not renaming!) however we've found that renaming them in this way minimizes the total amount of pain.

Could you provide a full set of repro steps that uses one of the Vcpkg integration mechanisms?

@ras0219-msft ras0219-msft added the requires:repro The issue is not currently repro-able label Sep 6, 2017
@VikingExplorer
Copy link
Author

1. https://github.com/Microsoft/vcpkg: download zip & extract 
2. VS dev Cmd prompt: cd vcpkg-folder
3. \vcpkg> bootstrap-vcpkg.bat
4. create triplet file
5. \vcpkg>vcpkg install cpprestsdk:x64-windows-static-md

I originally tried the integrate command, but it was a disaster. It fails the software prime directive that everything should be maintainable, and therefore discover-able.

Since my triplet specifies v141 and linking with CRT as DLL, the resulting lib files should be named appropriately.

@paul-michalik
Copy link

@VikingExplorer I maintain a fork of vcpkg exactly for this reason. I haven't completely understand the reasoning of vcpkg team for the Boost case since after removing the renaming steps everything always works as expected. We have added triplets for dynamic CRT linking and creation of static libraries instead of dlls.

@VikingExplorer
Copy link
Author

Since this seems to be still marked as "needs repro" (even though provided), I'll try to restate the problem more clearly:

x86-windows-static-md.cmake Triplet: (v141 is the default)
set(VCPKG_TARGET_ARCHITECTURE x86)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)

x64-windows-static-md.cmake Triplet:
set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_PLATFORM_TOOLSET v141)

Steps to reproduce:

	1. install 64 bit git (https://git-scm.com/download/win)
	2. Open VS dev Cmd prompt
	3. cd C:\Dev\3pLibs
	4. git clone https://github.com/Microsoft/vcpkg
	5. cd vcpkg
	6. bootstrap-vcpkg.bat
	7. open up VS -> Source Control Explorer
	8. Select files in $/3pLibs/vcpkg/triplets (make sure that our triplet files are downloaded)
	9. Right click, select "Check out for edit"  (Lock type: Unchanged)
	10. vcpkg install
		1. vcpkg install boost:x64-windows-static-md boost:x86-windows-static-md
		2. vcpkg install openssl:x64-windows-static-md openssl:x86-windows-static-md

Result: boost_system-vc140-mt-gd-1_66.lib

Building my project, I get: Linking to lib file: boost_system-vc141-mt-gd-1_66.lib

Error: not found.

My work around is to modify autolink.hpp:

#define BOOST_LIB_PREFIX ""
#define BOOST_LIB_ARCH_AND_MODEL_OPT ""
#define BOOST_LIB_TOOLSET "vc140"

I have to repeat this modification every time I update boost. It's a pain. Shouldn't have to.

@VikingExplorer
Copy link
Author

They have now dropped the version number all together. IMO, it's a design flaw.

I now have to modify autolink.hpp with every boost update, since it's not possible to use the normal boost customization's:

FROM:

#  pragma comment(lib, BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT BOOST_LIB_ARCH_AND_MODEL_OPT "-" BOOST_LIB_VERSION ".lib")
#  ifdef BOOST_LIB_DIAGNOSTIC
#     pragma message ("Linking to lib file: " BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT BOOST_LIB_ARCH_AND_MODEL_OPT "-" BOOST_LIB_VERSION ".lib")

TO:

#  pragma comment(lib, BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT BOOST_LIB_ARCH_AND_MODEL_OPT ".lib")
#  ifdef BOOST_LIB_DIAGNOSTIC
#     pragma message ("Linking to lib file: " BOOST_LIB_PREFIX BOOST_STRINGIZE(BOOST_LIB_NAME) "-" BOOST_LIB_TOOLSET BOOST_LIB_THREAD_OPT BOOST_LIB_RT_OPT BOOST_LIB_ARCH_AND_MODEL_OPT ".lib")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires:repro The issue is not currently repro-able
Projects
None yet
Development

No branches or pull requests

4 participants