New problem of C++ modules #4682
-
Visual Studio can compile while xmake cannot, with strange error - redefinition of add_rules("mode.debug", "mode.release")
set_languages("cxxlatest")
target("module-split-impl")
set_kind("binary")
add_files("*.cpp")
add_files("Person.mpp") main.cpp: import std;
import Person;
int main()
{
std::println("---------module-split-impl---------");
HelloWorld();
Person person{"Wow", 6};
person.Print();
return 0;
} Person.mpp: export module Person; // denote that it's a module interface.
import std;
export class Person
{
public:
Person(const std::string& init_name, std::uint64_t init_id);
void Print();
private:
std::string name;
std::uint64_t id;
};
export void HelloWorld(); Peron.cpp: module Person; // denote that it's a module implementation
import std;
Person::Person(const std::string& init_name, std::uint64_t init_id):
name{init_name}, id{init_id} {}
void Person::Print()
{
std::println("Person #{}: {}", id, name);
} Person-Func.cpp: module Person;
import std;
void HelloWorld()
{
std::println("Hello, world!");
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I also find that example of module partition in cppreference cannot be compiled in xmake. |
Beta Was this translation helpful? Give feedback.
-
@Arthapz Any idea? I have not latest vs version now. |
Beta Was this translation helpful? Give feedback.
-
I'm not sure whether it's related to another VS bug I report here. This example cannot be built either by VS or by xmake. |
Beta Was this translation helpful? Give feedback.
-
well it work on my side but i'm using VS 17.9.0 Preview 5 |
Beta Was this translation helpful? Give feedback.
there is an issue with .cpp modules currently
consider using .mpp / .cppm / .ixx for named module / module partition for now
i'll fix that later on