Search code examples
cmakedllgoogletest

Build gtest as shared library (dll) in CMake


I have never worked with CMake before, so please forgive any rookie mistakes. Most of the following working frame has been given to me by my project group. The goal is to build GoogleTest into a .dll, to be used in different, indepentent parts of our project. I'm having troubles setting up CMake the right way.

The work-flow so far has been:

  1. Clone gtest from git --> also downloads a CMake List file
  2. Alter variables in CMakeCache.txt to have it produce a Code::Blocks project file
  3. Compile the project file in Code::Blocks

So far, it produces a static library (.a files) that can be used in our project. I'm having troubles genereating .dll files. Variables I have tried changing:

  • BUILD_SHARED_LIBS:BOOL=ON --> the files generated by Code::Blocks now have a .dll.a double extension
  • CMAKE_C_FLAGS and all the corresponding C++ flags where set to -DGTEST_CREATE_SHARED_LIBRARY=1 as given here
  • CMAKE_EXE_LINKER_FLAGS has been set to -shared to make the linker produce .dll files

I have worked my way through the GoogleTest documentation here and here but in both, building it into a .dll is merely a 2-sentence-topic.


Solution

  • As @Tsyvarev pointed out, the .dll files were created in a (very) different folder.