libc++ 协程的 suspend_always::await_suspend 应该与 c++experimental.lib "exported"吗?
Is libc++ coroutine's suspend_always::await_suspend supposed to be "exported" to c++experimental.lib?
我在针对我构建的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
在此之前,我已经使用 libc++ 构建了 libc++-DLIBCXX_ENABLE_SHARED=YES
-DLIBCXX_ENABLE_STATIC=NO
-DLIBCXX_ENABLE_EXPERIMENTAL_LIBRARY=YES
set LIB=C:Program Files (x86)Microsoft Visual Studio2019BuildToolsVCToolsMSVC14.20.27508libx64;C:Program Files (x86)Windows Kits10Lib10.0.17763.0ucrtx64;C:Program Files (x86)Windows Kits10Lib10.0.17763.0umx64
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++.lib
和nm c++experimental.lib
.我没有发现suspend_always
的痕迹。
dll 中似乎缺少suspend_always::await_suspend
。所以我深入研究了一些 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_COFF
得很好defined
.
再往下,我们有
#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
我什至在构建libc++
时尝试了硬编码struct __declspec(dllexport) suspend_always
,结果仍然相同。
然后我突然想到了一个主意。我创建libcxx-master/src/experimental/coroutine
并使其#include <experimental/coroutine>
.重建libc++.dll
,事实证明这次工作正常。
我的问题是struct suspend_always
(和suspend_never
)是否真的应该出口到c++experimental.lib
?
我在哪里可以向实施者报告?
似乎是一个错误。它应该在 r358551 中修复。
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- JSON转换为nlohmann JSON-lib中的结构数组
- 为什么导入Mixed native/CLR lib.dll的本机C++应用程序没有在Mixed lib.dll中的外部变
- 使用 VS2015 在 Windows 10 上构建 Fortran .lib x64 位并将其链接到 C++
- 为什么我的链接器在找到Coin4d.lib后搜索Coin4sd.lib?
- libcpmtd.lib有什么用?
- LNK1104:无法打开libpjproject-i386-Win32-vc14-Debug-Static.lib
- 解析引用 |exe/dll vs lib
- 在 /usr/local/lib 下找不到库
- LLVM 编译:目标的配方 '../lib/IR/Release+Asserts/Intrinsics.gen.tmp' failed
- CMake 生成的 MSVC 项目找不到符号,即使为其相关 dll 正确生成了 lib 文件也是如此
- VS2015 未链接用户32.lib
- 从 .lib 文件创建一个.dll文件
- 看不到文件'SDL2.lib'
- 如何使用用户定义的函数覆盖 C lib 函数,如 _sbrk?
- 如何在不需要LIBCD.lib的情况下在Visual Studio 6中编译C项目
- 可执行文件C++包括.obj,.lib和.dll吗?
- 我应该安装 .cmake 文件来共享/cmake 还是 lib/cmake?
- 无法在 DLL 中链接 SDL2-static.lib
- 对使用 CMake 生成为 lib .a 的方法的未定义引用