Skip to content

[Windows] Solution for Issues Building on Windows #5

@riskydissonance

Description

@riskydissonance

For anyone else who encounters this when compiling googletest from GitHub on Windows you need to create the project with the -Dgtest_force_shared_crt=ON argument to cmake.

Without this you can get a lot of compilation errors such as:
gtest.lib(gtest-all.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MTd_StaticDebug' doesn't match value 'MDd_DynamicDebug'

See the googletest readme for more information: https://github.com/google/googletest/blob/master/googletest/README.md

Additionally the googletest directory structure has changed, and the example c2 CMakeLists.txt file links to pthread (for googletest) but isn't required for this test, so it can be removed.

My CMakeLists.txt file which works is:

# CMakeList.txt : Top-level CMake project file, do global configuration
# and include sub-projects here.
#
cmake_minimum_required (VERSION 3.8)

project ("Soundex1")

include_directories($ENV{GMOCK_HOME}/googletest/include $ENV{GMOCK_HOME}/googlemock/include)
link_directories($ENV{GMOCK_HOME}/mybuild/lib/MinSizeRel)

add_definitions(-std=c++0x)
set(CMAKE_CXX_FLAGS "${CMAXE_CXX_FLAGS} -Wall")

set(sources 
   main.cpp 
   SoundexTest.cpp)

add_executable(test ${sources})

target_link_libraries(test gmock)
target_link_libraries(test gtest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions