我正在使用模块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.h
和sched.h
的错误...
有没有人知道如何编译它?
(有关完整的错误消息,请参见此处:https://godbolt.org/g/wfjmpW)
答案 0 :(得分:0)
为了记录,我找到了(有点)更好的solution:
export module strings;
#if defined(__GXX_WEAK__)
#include <bits/gthr-default.h>
#endif
#include <string>
即使我需要在模块中#include <ctime>
,这也有效。