4

我正在使用模块 ts 测试一个简单的 C++ 模块:

export module strings;
#include <string>

当我尝试在 linux 上使用 clang (trunk) 和 GCC 7.2 头文件编译它时,我得到了这个:

clang++ -std=c++2a -fmodules-ts -fprebuilt-module-path=. --precompile -x c++-module -o strings.pcm ../../src/base/strings.cc
In file included from ../../src/base/strings.cc:2:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/string:52:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/bits/basic_string.h:39:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/c++/7.2.0/ext/atomicity.h:35:
In file included from /usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/x86_64-linux-gnu/c++/7.2.0/bits/gthr.h:148:
/usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/x86_64-linux-gnu/c++/7.2.0/bits/gthr-default.h:101:1: error: weakref declaration must have internal linkage
__gthrw(pthread_once)
^
/usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/x86_64-linux-gnu/c++/7.2.0/bits/gthr-default.h:99:23: note: expanded from macro '__gthrw'
#define __gthrw(name) __gthrw2(__gthrw_ ## name,name,name)
                      ^
/usr/lib/gcc/x86_64-linux-gnu/7.2.0/../../../../include/x86_64-linux-gnu/c++/7.2.0/bits/gthr-default.h:90:46: note: expanded from macro '__gthrw2'
  static __typeof(type) name __attribute__ ((__weakref__(#name2))); \
                                             ^

我试图预先包含<bits/gthr-default.h>(在 之前export module),但后来我收到关于time.hsched.h...的错误

有谁知道如何编译它?

(有关完整的错误消息,请参见此处:https ://godbolt.org/g/wfjmpW )

4

1 回答 1

3

作为记录,我找到了一个(有点)更好的解决方案

export module strings;
#if defined(__GXX_WEAK__)
#include <bits/gthr-default.h>
#endif

#include <string>

即使我需要#include <ctime>在模块内部,这也有效。

于 2018-01-10T10:41:41.780 回答