c++ - 无法在带有 Clang 的模块中使用对齐的“operator new”
问题描述
我正在尝试使用 Clang“模块”功能,并且正在尝试编译以下代码:
export module a;
#include <new>
export void *foo()
{
return ::operator new(1, std::align_val_t(1));
}
export int main() {}
当我尝试clang++ -std=c++2a -pedantic-errors -fmodules-ts --precompile -x c++-module a.cpp -o a.pcm
时,我得到了
error: ISO C++ requires a definition in this translation unit for function 'operator new' because its type does not have linkage [-Werror,-Wundefined-internal-type] a.cpp:7:14: note: used here return ::operator new(1, std::align_val_t(1)); ^ 1 error generated.
删除-pedantic-errors
修复了错误,但是当我尝试使用链接生成的模块时clang++ -std=c++2a -fmodules-ts a.pcm -o a.exe
,我得到
Z:\Lander\msys2\tmp\a-cfaf65.o:a.pcm:(.text+0x10): undefined reference to `_ZnwyW1aESt11align_val_t' clang++: error: linker command failed with exit code 1 (use -v to see invocation)
这特别烦人,因为<iostream>
(间接)似乎依赖于对齐operator new
,所以我也不能在模块中使用它。以及其他一些标准标题。
这里发生了什么?
这是一个 Clang 错误,我该如何解决?
My Clang 是 MSYS2 提供的最新版本:
# clang++ --version
clang version 8.0.0 (tags/RELEASE_800/final)
Target: x86_64-w64-windows-gnu
Thread model: posix
编辑:
提交了一个错误报告,让我们看看会发生什么......
解决方案
标准库不是您的模块的一部分a
。所以不要在export module a;
. 在此之前包含标题。
推荐阅读
- python - 如何使用 Selenium 和 Python 定位以下 html 的元素
- web-services - 如何从 Flutter/Dart Soap Web 服务 asmx 调用中获取价值?
- java - 搜索多列数组列表?
- angular - 无法读取 ngOnInit() Angular7 上未定义的属性“id”
- swift - stephencelis 的 Xcode 10.2 更新 SQLite.Swift 框架不起作用
- tcl - 给定键具有多个值的字典
- javascript - WL.JsonStore 未初始化,尝试在 Android 设备和 Android 模拟器中构建 cordova IBM Mobile First 应用程序时
- ios - 为什么 UITableView 没有获得任何用户交互,因为它的 ViewController 被添加到 UITabBarController 作为 subView
- docker - 访问在 Docker 容器上的主机上运行的 Web 应用程序
- python - 在列等于特定值的情况下,将新值插入新列 - Python