boostorg / boostorg/cobalt

Failure to compile cobalt channel in templated code.

Offen
#263 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C++
Sterne
347
Forks
47
Ø Merge
3 T. 8 Std.
Gemergte PRs (30 T.)
1

Beschreibung

I'm trying to use cobalt in conjunction with open62451pp to make calling asynchronous function more linear.

I've implemented a template like such:

```cpp
template
struct AsyncResult {

template
static auto initiate(Initiation&& initiation, UseCobaltToken, Args&&... args) -> boost::cobalt::task {

auto ex = co_await boost::cobalt::this_coro::executor;

auto channel = boost::cobalt::channel(1u, ex);

auto callback = [&channel, ex](auto&& res) mutable {
boost::cobalt::spawn(ex,
[](auto& chan, auto response) mutable -> boost::cobalt::task {
co_await chan.write(std::move(response));
}(channel, std::forward(res)),
boost::asio::detached
);
};

std::invoke(std::forward(initiation), std::move(callback), std::forward(args)...);

co_return co_await channel.read();
}
};
```
But when compiling, i get the following issue:

```
[2/2] Linking CXX executable play
FAILED: [code=1] play
: && /usr/bin/clang++-21 -g -fuse-ld=lld CMakeFiles/play.dir/main.cpp.o -o play vcpkg_installed/x64-linux-clang21/debug/lib/libfmtd.a vcpkg_installed/x64-linux-clang21/debug/lib/libboost_cobalt.a vcpkg_installed/x64-linux-clang21/debug/lib/libopen62541pp.a vcpkg_installed/x64-linux-clang21/debug/lib/libboost_date_time.a vcpkg_installed/x64-linux-clang21/debug/lib/libboost_container.a vcpkg_installed/x64-linux-clang21/debug/lib/libboost_context.a vcpkg_installed/x64-linux-clang21/debug/lib/libopen62541.a -lpthread -lm -lrt && :
ld.lld: error: undefined symbol: boost::asio::detail::cancellation_handler>::write_op::cancel_impl>::call(boost::asio::cancellation_type)
>>> referenced by main.cpp
>>> CMakeFiles/play.dir/main.cpp.o:(vtable for boost::asio::detail::cancellation_handler>::write_op::cancel_impl>)

ld.lld: error: undefined symbol: boost::asio::detail::cancellation_handler>::write_op::cancel_impl>::destroy()
>>> referenced by main.cpp
>>> CMakeFiles/play.dir/main.cpp.o:(vtable for boost::asio::detail::cancellation_handler>::write_op::cancel_impl>)
clang++-21: error: linker command failed with exit code 1 (use -v to see invocation)
```

I'm compiling with clang++-21 and linking with lld, although, linking with ld also failed.

Other uses of the channel in non templated code, following the example code did compile:
(It's using the same Type when instanciating the channel).

```
auto ex = co_await boost::cobalt::this_coro::executor;

auto chan = std::make_shared>>(1u, ex);

opcua::services::readValueAsync(client, node,
[chan, ex](opcua::Result res) {
fmt::println("Received value: {}, executing coroutine.", res.hasValue() ? "Success" : "Error");
boost::cobalt::spawn(ex,
[chan, r = std::move(res)](this auto) -> boost::cobalt::task {
co_await chan->write(std::move(r));
}(),
boost::asio::detached
);
});
```

Maybe it's a compiler bug on my end? I'm not sure.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.