How to build static multithread debug dll (MDd) / multithread dll (MD)

353 views
Skip to first unread message

Jiaqiang Bai

unread,
Sep 27, 2016, 2:39:01 PM9/27/16
to discuss-webrtc
I am building latest master branch webrtc for vs2015 using the new gn build but can't figure out how to get it to build MD runtime libraries.

Currently using these params
gn gen out/Debug --args="target_os=\"win\" target_cpu=\"x86\"" --ide="vs2015"
gn gen out/Release --args="is_debug=false target_os=\"win\" target_cpu=\"x86\"" --ide="vs2015"

Appreciate if someone can help with pointing out the gn params to change the library runtime to MD? 

Bernhard Höckner

unread,
Sep 28, 2016, 2:26:24 AM9/28/16
to discuss-webrtc
brute force: i change the cflags within chromium/src/build/config/win/BUILD.gn

maybe someone knows a better approach?

梁人生

unread,
Jun 12, 2017, 4:51:17 PM6/12/17
to discuss-webrtc
Many thanks!

I modify "if (current_os != "win")" to "if (current_os == "win")" in BUILD.gn and it works well

Sanket Diwale

unread,
May 17, 2022, 4:19:59 PMMay 17
to discuss-webrtc
I was looking at a similar problem for WebRTC build with VS2019 on windows (x64).

The  "src/build/config/win/BUILD.gn" file in this case seems to define different configs that can be used to control the type of linking used (MD, MT ...).

The relevant section of the file looks as follows:

```src/build/config/win/BUILD.gn
# Configures how the runtime library (CRT) is going to be used.
# See https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx for a reference of
# what each value does.
config("default_crt") {
  if (is_component_build) {
    # Component mode: dynamic CRT. Since the library is shared, it requires
    # exceptions or will give errors about things not matching, so keep
    # exceptions on.
    configs = [ ":dynamic_crt" ]
  } else {
    if (current_os == "winuwp") {
      # https://blogs.msdn.microsoft.com/vcblog/2014/06/10/the-great-c-runtime-crt-refactoring/
      # contains a details explanation of what is happening with the Windows
      # CRT in Visual Studio releases related to Windows store applications.
      configs = [ ":dynamic_crt" ]
    } else {
      # Desktop Windows: static CRT.
      configs = [ ":static_crt" ]
    }
  }
}

# Use this to force use of the release CRT when building perf-critical build
# tools that need to be fully optimized even in debug builds, for those times
# when the debug CRT is part of the bottleneck. This also avoids *implicitly*
# defining _DEBUG.
...

config("dynamic_crt") {
  if (is_debug) {
    # This pulls in the DLL debug CRT and defines _DEBUG
    cflags = [ "/MDd" ]
  } else {
    cflags = [ "/MD" ]
  }
}

config("static_crt") {
  if (is_debug) {
    # This pulls in the static debug CRT and defines _DEBUG
    cflags = [ "/MTd" ]
  } else {
    cflags = [ "/MT" ]
  }
}
```
 
I couldn't however figure out how to use the "gn gen out/Release --args=..." command line to choose which config to use. Any idea what the correct option/--args content needs to be added to choose one of these configs. I tried adding --crt="dynamic_crt" and other such things but that didn't seem to work. I'm somewhat unfamiliar with the gn command line tool to figure out what the correct naming/ arg call should look like. 

Cody Barnes

unread,
Aug 10, 2022, 12:57:33 AMAug 10
to discuss-webrtc
I couldn't find a better way to do it other than modifying chromium/src/build/config/win/BUILD.gn by making it sensitive to the libcxx_is_shared argument.
Honestly, I was too lazy to see if the build was using config("release_crt") or config("default_crt") so I changed both.

config("default_crt") {
  if (is_component_build) {
...
  } else {
    if (current_os == "winuwp" || libcxx_is_shared) {
...
    } else {
...
    }
  }
}

...
config("release_crt") {
  if (is_component_build || libcxx_is_shared) {
    cflags = [ "/MD" ]
...
    }
  } else {
    cflags = [ "/MT" ]
...
    }
  }
}

Then add libcxx_is_shared to the gn args
gn gen out\Release --args="libcxx_is_shared=true"

Reply all
Reply to author
Forward
0 new messages