用xmake来尝试c++的模块

target("a")
    set_kind("binary")
    add_files("*.cpp", "*.mpp")
    set_targetdir('.')
//放在当前目录,直接就可运行了,不用xmake run a
//xmake.lua

模块:

#include <cstdio>
export module a;
using namespace std;

export void say(const char* str) {
    printf("%s\n", str);
}//每个都要写导出,太烦人了.

主:

import a;

int main() {
    say("你好,模块");
    return 0;
}

注意,不要放在别的xmake之下.
命令:xmake,再xmake run a.

posted @ 2022-03-03 22:09  zjh6  阅读(19)  评论(0)    收藏  举报  来源