在CppCon的talk中,Richard Smith提到,即使Module TS支持目前正在進行中,它已經可以使用。所以我從svn構建了鏗鏘4.0,並在一個非常簡單的示例中嘗試了它。在我myclass.cppm
文件中我定義了一個簡單的包裝爲int
Clangs C++模塊TS支持:如何判斷clang ++在哪裏可以找到模塊文件?
module myclass;
export class MyClass {
public:
MyClass (int i)
: _i{i} {}
int get() {
return _i;
}
private:
int _i;
};
和我main.cpp
剛剛創建類的一個實例,並輸出其持有int
到std::cout
。
#include <iostream>
#include <string>
import myclass;
int main(int, char**) {
MyClass three{3};
std::cout << std::to_string(three.get()) << std::endl;
}
然後我試圖通過clang++ -std=c++1z -fmodules-ts main.cpp
與clang++ -std=c++1z -fmodules-ts myclass.cppm main.cpp
但不`噸的工作來編譯它,我得到在這兩種情況下相同的錯誤消息:
main.cpp:3:8: fatal error: module 'myclass' not found
import test.myclass;
~~~~~~~^~~~
1 error generated.
可惜我一直沒能找到文檔爲-fmodules-ts
。有人知道我可以如何讓clang ++編譯我的簡單例子嗎?
我不太確定,可能有意更好地指導構建系統需要重新編譯的內容。 – Corristo
但是構建系統如何知道編譯事物的順序呢?此外,構建系統需要累積模塊:如果模塊X依賴於模塊A和B,而模塊A依賴於模塊C,則需要構建以下命令行: –
clang ++ -std = C++ 1z -fmodules- ts --precompile -o X.pcm -fmodule-file = A.pcm -fmodule-file = B.pcm -fmodule-file = C.pcm X.cppm 這似乎不是要走的路。必須有某種查找機制。或者,至少,編譯器應該接受所有源文件的無序列表... –