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

Mismatch in linker when building on Windows, getting dynamic lib when static is needed #2452

Open
7sharp9 opened this issue Jan 26, 2025 · 7 comments

Comments

@7sharp9
Copy link

7sharp9 commented Jan 26, 2025

When Im building my code on windows I get these linker errors:

hwy.lib(targets.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in juce_audio_plugin_client_VST3.cpp.obj

hwy.lib(abort.cc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' in juce_audio_plugin_client_VST3.cpp.obj

Do you know why I would be getting a dynamic version on Windows, this does not occur on Mac?

Perhaps I forgot a flag or setting?

Im just bringing Highway in like this in my cmake:

FetchContent_Declare(highway
        EXCLUDE_FROM_ALL
        GIT_REPOSITORY https://github.com/google/highway.git
        GIT_TAG 9aa447ec5eb79af5ab9e583517c4b2e046a0cd09
)
set(HWY_ENABLE_TESTS OFF CACHE INTERNAL "")
set(BUILD_TESTING OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(highway)
@7sharp9 7sharp9 changed the title Mismatch when building getting dynamic lib when statis is needed Mismatch in linker when building on Windows, getting dynamic lib when static is needed Jan 26, 2025
@7sharp9
Copy link
Author

7sharp9 commented Jan 26, 2025

When I look at the cmake files generated in _deps the hwy project shows its using <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>:

  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <AdditionalIncludeDirectories>C:\Users\Dave\Documents\GitHub\StudioStandard\build_cmd\_deps\highway-src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <AdditionalOptions>%(AdditionalOptions) /bigobj /EHs-c-</AdditionalOptions>
      <AssemblerListingLocation>$(IntDir)</AssemblerListingLocation>
      <BasicRuntimeChecks>Default</BasicRuntimeChecks>
      <DisableSpecificWarnings>4100;4127;4324;4456;4701;4702;4723</DisableSpecificWarnings>
      <ExceptionHandling>Sync</ExceptionHandling>
      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
      <LanguageStandard>stdcpp17</LanguageStandard>
      <MinimalRebuild></MinimalRebuild>
      <Optimization>MaxSpeed</Optimization>
      <PrecompiledHeader>NotUsing</PrecompiledHeader>
      <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>

Any ideas?

@jan-wassenberg
Copy link
Member

Hi, I am not very familiar with CMake + MSVC, but we do provide some knobs to disable DLL:
-DBUILD_SHARED_LIBS=OFF or -DHWY_FORCE_STATIC_LIBS=ON.
Hope this helps?

@7sharp9
Copy link
Author

7sharp9 commented Jan 27, 2025

Thanks @jan-wassenberg I did already try that. I'm not sure why, although my cmake project is build statically the highway dependency is built dynamic.

I added this to try and force it:

set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
FetchContent_Declare(highway
        EXCLUDE_FROM_ALL
        GIT_REPOSITORY https://github.com/google/highway.git
        GIT_TAG 9aa447ec5eb79af5ab9e583517c4b2e046a0cd09
)
set(HWY_ENABLE_TESTS OFF)
set(BUILD_TESTING OFF)
set(HWY_ENABLE_CONTRIB OFF)
set(HWY_ENABLE_EXAMPLES OFF)
set(HWY_FORCE_STATIC_LIBS ON )
FetchContent_MakeAvailable(highway)

@7sharp9
Copy link
Author

7sharp9 commented Jan 27, 2025

@jan-wassenberg Have you had any builds using Windows cmake and clang?

@jan-wassenberg
Copy link
Member

hm, that looks reasonable.
Unfortunately our Windows build uses an internal toolchain which is not CMake.

These threads have some suggestions that might help?
https://discourse.cmake.org/t/mt-staticrelease-doesnt-match-value-md-dynamicrelease/5428/3
davisking/dlib#1448

@7sharp9
Copy link
Author

7sharp9 commented Jan 27, 2025

I tried removing different libs to check hwy was the cause and it was. I ended up forking and adding this which seemed to resolve it:

# Set CMP0091 to NEW to enable MSVC_RUNTIME_LIBRARY for all targets.
if(POLICY CMP0091)
  cmake_policy(SET CMP0091 NEW)
endif()

I was setting MSVC_RUNTIME_LIBRARY in my lib to MultiThreaded

@jan-wassenberg
Copy link
Member

Nice, good news. Would you like to send a pull request with that?

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

No branches or pull requests

2 participants