gpt4 book ai didi

c++ - libc++协程的suspend_always::await_suspend应该是 "exported"到c++experimental.lib吗?

转载 作者:行者123 更新时间:2023-11-28 04:19:54 25 4
gpt4 key购买 nike

针对我构建的 libc++ 编译协程时出现此错误

"C:\\Program Files\\LLVM\\bin\\lld-link" ... c++.lib c++experimental.lib ...
lld-link: error: undefined symbol: __declspec(dllimport) public: void __cdecl std::experimental::coroutines_v1::suspend_always::await_suspend(class std::experimental::coroutines_v1::coroutine_handle<void>) const

在此之前,我使用 -DLIBCXX_ENABLE_SHARED=YES 构建了 libc++ -DLIBCXX_ENABLE_STATIC=NO -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=YES

set LIB=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.20.27508\lib\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\ucrt\x64;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.17763.0\um\x64
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM="C:/Program Files (x86)/Ninja/ninja.exe" -DCMAKE_SYSTEM_NAME=Windows -DCMAKE_C_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_C_FLAGS="-fms-compatibility-version=19.20.27508 --target=x86_64-pc-windows-msvc19.20.27508" -DCMAKE_CXX_COMPILER="C:/Program Files/LLVM/bin/clang-cl.exe" -DCMAKE_CXX_FLAGS="-fms-compatibility-version=19.20.27508 --target=x86_64-pc-windows-msvc19.20.27508" -DCMAKE_C_LINK_EXECUTABLE="C:/Program Files/LLVM/bin/lld-link.exe" -DCMAKE_CXX_LINK_EXECUTABLE="C:/Program Files/LLVM/bin/lld-link.exe" -DLLVM_PATH="C:/Program Files/LLVM" -DLIBCXX_ENABLE_SHARED=YES -DLIBCXX_ENABLE_STATIC=NO -DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=YES "C:/libcxx-master"
ninja -j 2

所以我尝试了nm c++.libnm c++experimental.lib .我没有找到 suspend_always 的踪迹.

好像suspend_always::await_suspend dll中缺少。所以我研究了一些 C++ 宏。

C:/libcxx-master/CMakeLists.txt , 有 _LIBCPP_BUILDING_LIBRARY定义。

add_definitions(-D_LIBCPP_BUILDING_LIBRARY)

C:/libcxx-master/include/__config , 我们有

#if defined(__ELF__)
# define _LIBCPP_OBJECT_FORMAT_ELF 1
#elif defined(__MACH__)
# define _LIBCPP_OBJECT_FORMAT_MACHO 1
#elif defined(_WIN32)
# define _LIBCPP_OBJECT_FORMAT_COFF 1
#elif defined(__wasm__)
# define _LIBCPP_OBJECT_FORMAT_WASM 1
#else
# error Unknown object file format
#endif

我在 _WIN32所以我们有 _LIBCPP_OBJECT_FORMAT_COFFdefined .
再往下,我们有

#if defined(_LIBCPP_OBJECT_FORMAT_COFF)

#ifdef _DLL
# define _LIBCPP_CRT_FUNC __declspec(dllimport)
#else
# define _LIBCPP_CRT_FUNC
#endif

#if defined(_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS)
# define _LIBCPP_DLL_VIS
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
# define _LIBCPP_OVERRIDABLE_FUNC_VIS
# define _LIBCPP_EXPORTED_FROM_ABI
#elif defined(_LIBCPP_BUILDING_LIBRARY)
# define _LIBCPP_DLL_VIS __declspec(dllexport)
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS _LIBCPP_DLL_VIS
# define _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_DLL_VIS
# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllexport)
#else
# define _LIBCPP_DLL_VIS __declspec(dllimport)
# define _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS _LIBCPP_DLL_VIS
# define _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS
# define _LIBCPP_OVERRIDABLE_FUNC_VIS
# define _LIBCPP_EXPORTED_FROM_ABI __declspec(dllimport)
#endif

#define _LIBCPP_TYPE_VIS _LIBCPP_DLL_VIS
#define _LIBCPP_FUNC_VIS _LIBCPP_DLL_VIS
#define _LIBCPP_EXCEPTION_ABI _LIBCPP_DLL_VIS
#define _LIBCPP_HIDDEN
#define _LIBCPP_METHOD_TEMPLATE_IMPLICIT_INSTANTIATION_VIS
#define _LIBCPP_TEMPLATE_VIS
#define _LIBCPP_ENUM_VIS

#endif // defined(_LIBCPP_OBJECT_FORMAT_COFF)

这意味着当我们构建 libc++ 时,_LIBCPP_TYPE_VIS变成 __declspec(dllexport) .所以我们可以将具体类型导出到 DLL

当我们编译代码时,_LIBCPP_TYPE_VIS变成 __declspec(dllimport) .所以我们可以从 DLL 导入具体类型

experimental/coroutine文件包括experimental/__config其中包括 __config并包含此 struct suspend_always定义

struct _LIBCPP_TYPE_VIS suspend_always {
_LIBCPP_INLINE_VISIBILITY
bool await_ready() const _NOEXCEPT { return false; }
_LIBCPP_INLINE_VISIBILITY
void await_suspend(coroutine_handle<>) const _NOEXCEPT {}
_LIBCPP_INLINE_VISIBILITY
void await_resume() const _NOEXCEPT {}
};

所以当我们构建 libc++ 时,我们有 struct __declspec(dllexport) suspend_always .当我们编译时,我们有 struct __declspec(dllimport) suspend_always

我什至尝试过硬编码 struct __declspec(dllexport) suspend_always build 时libc++ ,结果还是一样。


然后我想到了一个主意。我创建 libcxx-master/src/experimental/coroutine就让它成为#include <experimental/coroutine> .重建 libc++.dll事实证明这次工作正常。

我的问题是struct suspend_always是否(和 suspend_never )真的 应该导出到 c++experimental.lib

我在哪里可以将此报告给实现者?

最佳答案

似乎是一个错误。它应该在 r358551 中修复。

关于c++ - libc++协程的suspend_always::await_suspend应该是 "exported"到c++experimental.lib吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55704187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com