aleck099
aleck099

Reputation: 437

How can I make my own std.core module declaration?

Since modules are introduced to C++ in C++20, however, the std library itself can't be imported as modules until C++23.

I want to write code like import std.core; so I tries to make my own std library, simply exporting some classes and objects from std::.

The file stdcore.mpp looks like this:

module;
#include <string>
#include <string_view>

export module stdcore;

// This function will never be used.
// it only exports std::string and std::string_view.
export void __105aw1d065adw__(std::string,
    std::string_view); 

And main.cxx:

import stdcore;

int main()
{
    std::string s{"Hello world!"};
    return 0;
}

Compile them with these:

CXX="clang++ -fmodules-ts -std=c++20 -Wall"
$CXX --precompile -x c++-module stdcore.mpp

Everything looks well, but when I executes this:

$CXX main.cxx -c -fmodule-file=stdcore.pcm

I got:

main.cxx:5:2: error: missing '#include <string>'; 'std' must be declared before it is used
        std::string s{"Hello world!"};
        ^
E:\msys64\mingw64\include\c++\10.2.0\string:117:11: note: declaration here is not visible
namespace std _GLIBCXX_VISIBILITY(default)
          ^
1 error generated.

What does that mean?

Upvotes: 1

Views: 512

Answers (1)

Jarod42
Jarod42

Reputation: 217135

// This function will never be used.
// it only exports std::string and std::string_view.
export void __105aw1d065adw__(std::string, std::string_view); 

No, you only export that function, std::string/std::string_view are not exported.

Instead, it should be something like:

export module stdcore;

export import <string>;
export import <string_view>;
// ...

Upvotes: 2

Related Questions