andreasbuhr / cppcoro

A library of C++ coroutine abstractions for the coroutines TS
MIT License
364 stars 53 forks source link

Windows/MinGW: implicit instantiation of undefined template on socket_helpers #72

Closed kassane closed 1 year ago

kassane commented 1 year ago

My fork build log: https://github.com/kassane/cppcoro/actions/runs/5326844101

 clang failed with stderr: D:\a\cppcoro\cppcoro\lib\socket_helpers.cpp:52:43: error: implicit instantiation of undefined template 'std::reference_wrapper<sockaddr_storage>'
C:\hostedtoolcache\windows\zig\master\x64\lib\libcxx\include/__functional/unwrap_ref.h:25:7: note: template is declared here
D:\a\cppcoro\cppcoro\lib\socket_helpers.cpp:77:33: error: no viable overloaded '='
C:\hostedtoolcache\windows\zig\master\x64\lib\libc\include\any-windows-any/ws2def.h:28:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const _SCOPE_ID' for 1st argument
C:\hostedtoolcache\windows\zig\master\x64\lib\libc\include\any-windows-any/ws2def.h:28:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'int' to '_SCOPE_ID' for 1st argument
D:\a\cppcoro\cppcoro\lib\socket_helpers.cpp:52:43: warning: unused parameter 'address' [-Wunused-parameter]
andreasbuhr commented 1 year ago

Your title talks about MinGW, but the error message states you are compiling with Clang. Can you clarify please? What standard library do you use? The error message states that "C:\hostedtoolcache\windows\zig\master\x64\lib\libcxx" is used. What kind of library is that?

kassane commented 1 year ago

The title is not wrong! Target is mingw equivalent to llvm-mingw or msys2/clang64 both use libc++ instead of libstdc++.

zig toolchain is pure-llvm (builtin-tools: clang/++ + libcxx + libunwind + (custom)-libcompiler-rt + lld or zld(macOS only)]) based and currently for windows the default target is mingw (x86, x86_64, arm64).

However LLVM doesn't provide a full mingw support, with no add-on libraries like posix support.

Error happens with this function. https://github.com/andreasbuhr/cppcoro/blob/6863ac6f2e2e421c289460fc7cc88f3dda2d5fc8/lib/socket_helpers.cpp#L50-L83

mingw-w64 - ws2def https://github.com/mingw-w64/mingw-w64/blob/master/mingw-w64-headers/include/ws2def.h and zig-mingw - ws2def https://github.com/ziglang/zig/blob/master/lib/libc/include/any-windows-any/ws2def.h they are both identical!

except: https://github.com/tpn/winsdk-10/blob/master/Include/10.0.16299.0/shared/ws2def.h

References:

andreasbuhr commented 1 year ago

Thanks for clarifying.

The first error says that std::reference_wrapper is undefined. Does it help to #include <functional> in cppcoro/lib/socket_helpers.cpp?

kassane commented 1 year ago

Thanks for clarifying.

The first error says that std::reference_wrapper is undefined. Does it help to #include <functional> in cppcoro/lib/socket_helpers.cpp?

keep (w/ -DSCOPEID_UNSPECIFIED_INIT=1):

clang failed with stderr: /home/kassane/Documentos/cppcoro/lib/socket_helpers.cpp:78:33: error: no viable overloaded '='
/home/kassane/zig/0.11.0-dev.3773+438d68091/files/lib/libc/include/any-windows-any/ws2def.h:28:16: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from 'int' to 'const _SCOPE_ID' for 1st argument
/home/kassane/zig/0.11.0-dev.3773+438d68091/files/lib/libc/include/any-windows-any/ws2def.h:28:16: note: candidate function (the implicit move assignment operator) not viable: no known conversion from 'int' to '_SCOPE_ID' for 1st argument

_SCOPE_ID from ws2def.h (gnu).

On windows with msbuild(vc++) it worked. Have you tried running the library with mingw?

--- update

My fork, I have removed -DSCOPEID_UNSPECIFIED_INIT=1. Because, MinGW no has SCOPEID_UNSPECIFIED_INIT.

/home/kassane/Documentos/cppcoro/lib/socket_helpers.cpp:77:35: error: use of undeclared identifier 'SCOPEID_UNSPECIFIED_INIT'
/home/kassane/Documentos/cppcoro/lib/socket_helpers.cpp:52:43: warning: unused parameter 'address' [-Wunused-parameter]
andreasbuhr commented 1 year ago

I did not try mingw.

in https://github.com/tpn/winsdk-10/blob/9b69fd26ac0c7d0b83d378dba01080e93349c2ed/Include/10.0.10240.0/shared/ws2def.h#L625C1-L625C42 you can see that SCOPEID_UNSPECIFIED_INIT is defined to be "{ 0 }". Could you try that?

I don't know the right escaping, but something like -DSCOPEID_UNSPECIFIED_INIT={0} or -DSCOPEID_UNSPECIFIED_INIT={0} or so

kassane commented 1 year ago

Fine!!

Now...

tests error:

error: lld-link: undefined symbol: WaitOnAddress
    note: referenced by /home/kassane/Documentos/cppcoro/lib/lightweight_manual_reset_event.cpp:52
    note:               cppcoro.lib(lightweight_manual_reset_event.obj):(cppcoro::detail::lightweight_manual_reset_event::wait())
error: lld-link: undefined symbol: WakeByAddressAll
    note: referenced by /home/kassane/Documentos/cppcoro/lib/lightweight_manual_reset_event.cpp:30
    note:               cppcoro.lib(lightweight_manual_reset_event.obj):(cppcoro::detail::lightweight_manual_reset_event::set())

synchapi.h feature.

andreasbuhr commented 1 year ago

Could you double-check that you link to synchronization.lib ?

kassane commented 1 year ago

Could you double-check that you link to synchronization.lib ?

No have synchonization.lib on mingw.

Fixed - add in config.hpp: https://github.com/kassane/cppcoro/commit/fc8597bb1b0702a5b652a39fb8b522d67178e764

#ifdef __MINGW32__
#define _WIN32_WINNT 0x0601
#endif
build log ```bash Build Summary: 60/60 steps succeeded install success ├─ install include/ success ├─ install cppcoro success │ └─ zig build-lib cppcoro Debug native-windows success 5s MaxRSS:207M ├─ install async_auto_reset_event_tests success │ └─ zig build-exe async_auto_reset_event_tests Debug native-windows success 6s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install async_manual_reset_event_tests success │ └─ zig build-exe async_manual_reset_event_tests Debug native-windows success 6s MaxRSS:254M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install single_consumer_async_auto_reset_event_tests success │ └─ zig build-exe single_consumer_async_auto_reset_event_tests Debug native-windows success 6s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install async_latch_tests success │ └─ zig build-exe async_latch_tests Debug native-windows success 6s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install async_generator_tests success │ └─ zig build-exe async_generator_tests Debug native-windows success 11s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install async_mutex_tests success │ └─ zig build-exe async_mutex_tests Debug native-windows success 11s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install generator_tests success │ └─ zig build-exe generator_tests Debug native-windows success 9s MaxRSS:259M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install cancellation_token_tests success │ └─ zig build-exe cancellation_token_tests Debug native-windows success 16s MaxRSS:471M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install recursive_generator_tests success │ └─ zig build-exe recursive_generator_tests Debug native-windows success 9s MaxRSS:254M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install shared_task_tests success │ └─ zig build-exe shared_task_tests Debug native-windows success 10s MaxRSS:254M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install single_producer_sequencer_tests success │ └─ zig build-exe single_producer_sequencer_tests Debug native-windows success 16s MaxRSS:259M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install multi_producer_sequencer_tests success │ └─ zig build-exe multi_producer_sequencer_tests Debug native-windows success 16s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install sequence_barrier_tests success │ └─ zig build-exe sequence_barrier_tests Debug native-windows success 16s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install task_tests success │ └─ zig build-exe task_tests Debug native-windows success 11s MaxRSS:252M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install sync_wait_tests success │ └─ zig build-exe sync_wait_tests Debug native-windows success 6s MaxRSS:259M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install when_all_tests success │ └─ zig build-exe when_all_tests Debug native-windows success 7s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install when_all_ready_tests success │ └─ zig build-exe when_all_ready_tests Debug native-windows success 6s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install static_thread_pool_tests success │ └─ zig build-exe static_thread_pool_tests Debug native-windows success 6s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install ip_address_tests success │ └─ zig build-exe ip_address_tests Debug native-windows success 7s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install ip_endpoint_tests success │ └─ zig build-exe ip_endpoint_tests Debug native-windows success 7s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install ipv4_address_tests success │ └─ zig build-exe ipv4_address_tests Debug native-windows success 8s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install ipv4_endpoint_tests success │ └─ zig build-exe ipv4_endpoint_tests Debug native-windows success 8s MaxRSS:257M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install ipv6_address_tests success │ └─ zig build-exe ipv6_address_tests Debug native-windows success 11s MaxRSS:255M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install ipv6_endpoint_tests success │ └─ zig build-exe ipv6_endpoint_tests Debug native-windows success 11s MaxRSS:254M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install socket_tests success │ └─ zig build-exe socket_tests Debug native-windows success 11s MaxRSS:254M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install io_service_tests success │ └─ zig build-exe io_service_tests Debug native-windows success 9s MaxRSS:258M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) ├─ install scheduling_operator_tests success │ └─ zig build-exe scheduling_operator_tests Debug native-windows success 7s MaxRSS:255M │ ├─ zig build-lib cppcoro Debug native-windows (reused) │ └─ install include/ (reused) └─ install file_tests success └─ zig build-exe file_tests Debug native-windows success 11s MaxRSS:257M ├─ zig build-lib cppcoro Debug native-windows (reused) └─ install include/ (reused) ```