How to build a Visual Studio 2019 compatible webrtc library for Windows?

536 views
Skip to first unread message

天堂的回响

unread,
Jun 11, 2020, 5:35:54 AM6/11/20
to discuss-webrtc
I downloaded a Windows version webrtc source and compiled it successfully recently(on April 17th), but I can't use an gn compiled shared library based on the webrtc static library with Visual Studio 2019.

I wrote a shared library based on the 'webrtc' static library and it's testing executable with gn script under 'examples' directory.The executable and the shared library all worked well.But, when I use this shared library in a project directly created by Visual Studio 2019 IDE the functions in the shared library can't receive params correctly!For exmaple, there is a function named 'fun1' in the shared library, it takes 2 input parameters,the first one is an int, the second one is an std::string.When I call 'fun1' in the app and pass "webrtc" and 123 as the two parameters, the fun1 received " ???" and 123, where the first parameter's value changed to a unrecognizable value.

Firstly, I didn't set 'is_clang' in args to use clang-cl as the webrtc compiler and use clang-cl in Visual Studio.Secondly, I set  'is_clang=false' to use msvc as the compiler, and use msvc in Visual Studio 2019.The problem persists.

Was this caused by linking to a wrong c runtime library?I have changed the c runtime library link style to 'dynamic' in gn script under 'build/config/win/'.But, whether the link style is static or dynamic the problem persists.

Is there something wrong in my steps?

Eric Davies

unread,
Jun 11, 2020, 2:25:40 PM6/11/20
to discuss-webrtc
if I was debugging this, the first thing I'd be checking is:
  is 'int' the same size on both sides?
Ie, it could be 32 bit on one side and 64 bit on the other side.
One of the worst design flaws of the C language.
Try calling a function that only takes a single int and see what happens to it.

Second, I'd try verify that the string type you are passing is correct. Visual studio C++ has a number of different string type possibilities ( C style null terminated strings, C++ style strings in 8 bit and 16 bit flavors, plus another string type used for UI stuff).

Alexandre GOUAILLARD

unread,
Jun 11, 2020, 5:15:23 PM6/11/20
to discuss...@googlegroups.com
what s the error log?

--

---
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/119a5321-1f94-45f4-9442-3911e8573882o%40googlegroups.com.


--
Alex. Gouaillard, PhD, PhD, MBA
------------------------------------------------------------------------------------
President - CoSMo Software Consulting, Singapore
------------------------------------------------------------------------------------

天堂的回响

unread,
Jun 11, 2020, 11:27:49 PM6/11/20
to discuss-webrtc
Thanks for your reply!The int like parameters seems no problem, the problem occured in std::string parameters currently, so I think the problem is caused by libc++ libraries.I found the webrtc use a libc++ library built by it self, however Visual Studio seems use another c++ library in it's environment .And I found there is a building parameter named 'use_custom_libcxx' in the gn args list which can switching to using Visual Studio c++ library!When I set 'use_custom_libcxx=false' and 'is_clang=false is_debug=false', use the shared library in release mode the problem resolved!Thanks for your help again!

在 2020年6月12日星期五 UTC+8上午2:25:40,Eric Davies写道:

天堂的回响

unread,
Jun 11, 2020, 11:34:20 PM6/11/20
to discuss-webrtc
The strange thing is just that there is no error reported!The problem is resolved, it caused by linking different c++ standard library in dll and executable.
BTW, I found that the dll built by clang-cl can't linked by executables built by msvc, which will cause heap errors otherwise.

在 2020年6月12日星期五 UTC+8上午5:15:23,Alexandre GOUAILLARD写道:
what s the error log?

On Thu, Jun 11, 2020 at 8:25 PM Eric Davies <ericthe...@gmail.com> wrote:
if I was debugging this, the first thing I'd be checking is:
  is 'int' the same size on both sides?
Ie, it could be 32 bit on one side and 64 bit on the other side.
One of the worst design flaws of the C language.
Try calling a function that only takes a single int and see what happens to it.

Second, I'd try verify that the string type you are passing is correct. Visual studio C++ has a number of different string type possibilities ( C style null terminated strings, C++ style strings in 8 bit and 16 bit flavors, plus another string type used for UI stuff).




On Thursday, June 11, 2020 at 2:35:54 AM UTC-7, 天堂的回响 wrote:
I downloaded a Windows version webrtc source and compiled it successfully recently(on April 17th), but I can't use an gn compiled shared library based on the webrtc static library with Visual Studio 2019.

I wrote a shared library based on the 'webrtc' static library and it's testing executable with gn script under 'examples' directory.The executable and the shared library all worked well.But, when I use this shared library in a project directly created by Visual Studio 2019 IDE the functions in the shared library can't receive params correctly!For exmaple, there is a function named 'fun1' in the shared library, it takes 2 input parameters,the first one is an int, the second one is an std::string.When I call 'fun1' in the app and pass "webrtc" and 123 as the two parameters, the fun1 received " ???" and 123, where the first parameter's value changed to a unrecognizable value.

Firstly, I didn't set 'is_clang' in args to use clang-cl as the webrtc compiler and use clang-cl in Visual Studio.Secondly, I set  'is_clang=false' to use msvc as the compiler, and use msvc in Visual Studio 2019.The problem persists.

Was this caused by linking to a wrong c runtime library?I have changed the c runtime library link style to 'dynamic' in gn script under 'build/config/win/'.But, whether the link style is static or dynamic the problem persists.

Is there something wrong in my steps?

--

---
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...@googlegroups.com.

Alexandre GOUAILLARD

unread,
Jun 12, 2020, 7:25:00 PM6/12/20
to discuss...@googlegroups.com
I guess it was documented somewhere on the web ...


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/8866ab1c-3c5b-4a36-b189-de1e95caf7eeo%40googlegroups.com.
Message has been deleted

天堂的回响

unread,
Jun 14, 2020, 9:23:45 PM6/14/20
to discuss-webrtc
Thanks for sharing!I found the 'enable_iterator_debugging' arg is also very important on windows platform.If I set 'is_debug=true' I must set 'enable_iterator_debugging=true' too, otherwise the std::string value passing problem will occur again.

在 2020年6月13日星期六 UTC+8上午7:25:00,Alexandre GOUAILLARD写道:
Reply all
Reply to author
Forward
0 new messages