1

Our project structured like this.

1) MainApp, it loads dlls dynamically by using boost, and all the dlls projects/modules are build with /MD.

2) Any other projects that is needed by these dlls are built as static (.lib) or dynamic (.dll) lib. There is no problem when these dependency libraries are dynamic since I can use the same MD. However, if those are static, I have to build them with MD instead of default MT, otherwise it can't be loaded in these dlls.

This has worked all the times until I am trying to compile google cloud sdk c++.

Here is the problem: Google cloud c++ sdk has many dependencies that come with the google git, BUT Google only include (or build default) the static(/MT) version. And they don't even provide options to change to MD. I can change the google cloud lib from /MT to /MD by using cmake command set(CMAKE_CXX_FLAGS_RELEASE "/MD"), but this won't build because its dependency are /MT.

Simplified situation:

MainApp.exe dynamic loads -> Function.dll (/MD), then Function.dll static links Google_cloud.lib (.lib but with /MD), then Google_cloud.lib static link its dependencies (.lib with /MT, can't change it to /MD)

So I guess the only option is to manually custom build google cloud's static dependency with /MD and then build google cloud as static with /MD then loaded by my function.dll as static.

Any suggestion?

drescherjm
  • 10,365
  • 5
  • 44
  • 64
Peter
  • 21
  • 1
  • 3
  • My advice is to use the same runtime for all parts of your program (well except for debug configuration which requires debug runtimes). – drescherjm Jul 15 '19 at 18:36

1 Answers1

0

You can mutate the BUILD_SHARED_LIBS flags which will cause the default library type to be shared libraries.

Another way is simply to pass the right argument to the add_library command:

add_library(lib1 SHARED a.cpp b.cpp)
add_library(lib2 STATIC a.cpp b.cpp)
add_library(lib3 a.cpp b.cpp) # use the BUILD_SHARED_LIBS value
Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141