Thread overview
Linking objects built with MingW on windows
Apr 10
ronnie-w
Apr 10
kinke
Apr 12
ronnie-w
April 10

I tried linking an object built with MingW with the command

g++ -c libs/webview/webview.cc --std=c++14 -Ilibs/webview2 -DWEBVIEW_STATIC -mwindows -static-libgcc -static-libstdc++ -o webview.o

In my source root dir, I tried:

dmd app.d .\webview.d .\webview.o advapi32.lib ole32.lib shell32.lib shlwapi.lib user32.lib version.lib -extern-std=c++14

But most of the errors I get (from lld-link.exe) seem to stem from undefined symbols from c++11:

lld-link: error: undefined symbol: _ZTVN10__cxxabiv117__class_type_infoE
>>> referenced by .\webview.obj:(_ZTIZZ12webview_bindENKUlvE_clEvEUlRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_PvE_)
>>> referenced by .\webview.obj:(_ZTIZZ16webview_dispatchENKUlvE_clEvEUlvE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail11engine_base10on_messageERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEUlvE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail11engine_base28deplete_run_loop_event_queueEvEUlvE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail11engine_base28deplete_run_loop_event_queueEvEUlvE0_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail11engine_base21dispatch_size_defaultEvEUlvE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail17win32_edge_engine20add_user_script_implERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEUllPKwE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail17win32_edge_engine20add_user_script_implERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEUlvE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail17win32_edge_engine20add_user_script_implERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEUlPNS0_11user_script4implEE_)
>>> referenced by .\webview.obj:(_ZTIZN7webview6detail17win32_edge_engine5embedEP6HWND__bSt8functionIFvNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEUlP23ICoreWebView2ControllerP13ICoreWebView2E_)
>>> referenced 7 more times

lld-link: error: undefined symbol: _ZTVN10__cxxabiv120__si_class_type_infoE
>>> referenced by .\webview.obj:(_ZTIN7webview9exceptionE)
>>> referenced by .\webview.obj:(_ZTISt5_BindIFZN7webview6detail11engine_base7resolveERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEiSA_EUlS8_E_S8_EE)
>>> referenced by .\webview.obj:(_ZTISt5_BindIFMN7webview6detail11engine_baseEFvRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEPNS1_17win32_edge_engineESt12_PlaceholderILi1EEEE)
>>> referenced by .\webview.obj:(_ZTIN7webview6detail10bad_accessE)
>>> referenced by .\webview.obj:(_ZTIN7webview6detail17win32_edge_engineE)
>>> referenced by .\webview.obj:(_ZTIN7webview6detail34webview2_user_script_added_handlerE)
>>> referenced by .\webview.obj:(_ZTI57ICoreWebView2CreateCoreWebView2ControllerCompletedHandler)
>>> referenced by .\webview.obj:(_ZTI58ICoreWebView2CreateCoreWebView2EnvironmentCompletedHandler)
>>> referenced by .\webview.obj:(_ZTI64ICoreWebView2AddScriptToExecuteOnDocumentCreatedCompletedHandler)
>>> referenced by .\webview.obj:(_ZTI43ICoreWebView2WebMessageReceivedEventHandler)
>>> referenced 5 more times

and much much more ...

... and also from ldc2:

lld-link: error: undefined symbol: vtable for __cxxabiv1::__class_type_info
>>> referenced by .\webview.obj:(typeinfo for webview_bind::'lambda'()::operator()() const::'lambda'(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, void*))
>>> referenced by .\webview.obj:(typeinfo for webview_dispatch::'lambda'()::operator()() const::'lambda'())
>>> referenced by .\webview.obj:(typeinfo for webview::detail::engine_base::on_message(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)::'lambda'())
>>> referenced 14 more times

lld-link: error: undefined symbol: vtable for __cxxabiv1::__si_class_type_info
>>> referenced by .\webview.obj:(typeinfo for webview::exception)
>>> referenced by .\webview.obj:(typeinfo for std::_Bind<webview::detail::engine_base::resolve(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)::'lambda'(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>) (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)>)
>>> referenced by .\webview.obj:(typeinfo for std::_Bind<void (webview::detail::engine_base::* (webview::detail::win32_edge_engine*, std::_Placeholder<1>))(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)>)
>>> referenced 12 more times
...

I've tried changing extern-std to c++11 but it also fails. I've also tried linking with libstd++ from my local MingW installation but I get something along the lines of

duplicate symbol: ___xxx___xxxxx
   libstdc++

Building the g++ as a standalone exe with the libs advapi32.lib ole32.lib shell32.lib shlwapi.lib user32.lib version.lib and --std=c++14 produces an exe that works as expected.

I'm probably doing the linking wrong.

April 10

MinGW isn't supported by DMD and LDC. If you can't use an MS Visual C++ toolchain to build that webview.obj (and all libs it depends on), you could give GDC a try.

April 12

On Thursday, 10 April 2025 at 13:44:19 UTC, kinke wrote:

>

MinGW isn't supported by DMD and LDC. If you can't use an MS Visual C++ toolchain to build that webview.obj (and all libs it depends on), you could give GDC a try.

This question was actually dumb, dmd and ldc do support MingW:
I should have created a .lib file instead of using the object file directly:

g++ -c libs/webview/webview.cc -std=c++14 -Ilibs/webview2 -static-libstdc++ -static-libgcc -DWEBVIEW_STATIC -o webview.o

ar r webview.lib webview.o

... and used that with dmd/ldc instead.
For the duplicate symbols in ldc adding the flag --mscrtlib=<libcmt[d]|msvcrt[d]> worked.