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

702 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 PM5/17/22
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 AM8/10/22
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"

Điền Đô

unread,
Oct 5, 2023, 11:08:21 AM10/5/23
to discuss-webrtc
HI 梁人生.

I am new to webrtc. When I changed the BUILD.gn file and did a rebuild of the webrtc library it failed.
I want to ask, when we change the BUILD.gn file to rebuild the webrtc library, are there any notes?
I did with the following process:
1. Add macro definitions in BUILD.gn => save file
2. Run the gn gen command
And I failed here getting "Undefined identifier" error

I have posted my problem here: https://groups.google.com/g/discuss-webrtc/c/udn79Nswe8w/m/hwcv1byTAgAJ
I just need some suggestions or keywords to search online. 
I'm grateful for all the help:))

Thanks:))

Vào lúc 03:51:17 UTC+7 ngày Thứ Ba, 13 tháng 6, 2017, 梁人生 đã viết:

V I

unread,
Oct 5, 2023, 11:36:08 PM10/5/23
to discuss...@googlegroups.com
just remove the output folder completely before running "gn gen" again

--
This list falls under the WebRTC Code of Conduct - https://webrtc.org/support/code-of-conduct.
---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/b2fd6100-5c6a-4032-8e1f-c5561fc8ce6en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages