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

[BUG] MSVC 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MT_StaticRelease' #1655

Open
lishaojiang opened this issue Aug 23, 2023 · 1 comment

Comments

@lishaojiang
Copy link

lishaojiang commented Aug 23, 2023

Describe the bug
A clear and concise description of what the bug is.

I have download and compile and test Google BenchMark success on My Linux, My Mac. but On My Windows PC , I get an error when other project link the benchmark!

I know this is because the benchmark project is a lib generated by MD, but the test project regards it as MT, so the link is wrong.

I am forced to manually modify the benchmark attribute to MT then build and then manually copy it to the installation directory . it can work well.

I have tried the code below adding to CMakeLists.txt, it don't work!

if (MSVC)
     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
endif

or adding MT to the build script, but it has no effect!
cmake -E chdir "build" cmake -DCMAKE_CXX_FLAGS_RELEASE=/MT -DCMAKE_CXX_FLAGS=/MT -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../

System
Which OS, compiler, and compiler version are you using:

  • OS: windows 11,22H2,22621.2134
  • Compiler and version: Microsoft Visual Studio Professional 2022 (64-bit) - Current
    Version 17.6.5

To reproduce
Steps to reproduce the behavior:
install.bat

git clone https://github.com/google/benchmark.git
cd benchmark
cmake -E make_directory "build"
cmake -E chdir "build" cmake -DCMAKE_CXX_FLAGS_RELEASE=/MT -DCMAKE_CXX_FLAGS=/MT -DBENCHMARK_DOWNLOAD_DEPENDENCIES=on -DCMAKE_BUILD_TYPE=Release ../
cmake --build "build" --config Release --target install

then other project use the google bench

CMakeLists.txt

find_package(benchmark REQUIRED)
target_link_libraries(main PUBLIC benchmark::benchmark)
target_link_libraries(main PUBLIC benchmark::benchmark_main) 

Expected behavior
A clear and concise description of what you expected to happen.
How Can fix the google benchmark MD to MT auto

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context
Add any other context about the problem here.

@lishaojiang
Copy link
Author

well done , I find one solution!
Just use bleow code in Google BenchMark every CMakeLists.txt file! I find 4 cmakelists.txt file in my pc!

if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
    add_compile_options(/MT)
endif()

The original method didn't work, anyone know why

if (MSVC)
     set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MT")
endif

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

No branches or pull requests

2 participants