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

Static linking with MSVC and PRECOMPILED=ON #1066

Closed
wants to merge 2 commits into from

Conversation

timkruse
Copy link

Solves the following issue:

Using CLI11 with the option CLI11_PRECOMPILED=ON results in the following linking error (Windows10 + MSVC set up to link statically)

CLI11.lib(Precompile.cpp.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in srcfile.cpp.obj

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e4ee3af) to head (d6e26ee).
Report is 35 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main     #1066    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           17        17            
  Lines         4546      4583    +37     
  Branches         0       983   +983     
==========================================
+ Hits          4546      4583    +37     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@phlptp
Copy link
Collaborator

phlptp commented Aug 22, 2024

what would a CI build look like that would have caught this error?

@timkruse
Copy link
Author

timkruse commented Aug 22, 2024

Changing my application that includes CLI11 back to dynamic linking brings back the linking error from above but with swapped MD_DynamicRelease and MT_StaticRelease. So this PR is pointless, sorry.

For documentation purposes:
I want a statically linked executable on Windows with MSVC and use CLI11_PRECOMPILED=ON. Therefore, I have to put

set_property(TARGET myApp PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

in my CMakeLists.txt. That line alone raises the linking error shown above. To fix it CLI11 needs to be compiled with the same MSVC_RUNTIME_LIBRARY flags, but it can be placed in my CMakeLists.txt, too:

set_property(TARGET CLI11 PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

@timkruse timkruse closed this Aug 22, 2024
@phlptp
Copy link
Collaborator

phlptp commented Aug 22, 2024

I have vague recollections of having something like this in another library, I will poke around and see if anything should be done differently to make it a little smoother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants