How do I import a module from another project within the same Visual Studio solution?
I'm new to C++ modules. I have a project MyProject which includes a module definition Model.ixx:
export module Model; export import :Element;
And a partition in Element.ixx:
#include <string> export module Model:Element; export class Element { private: std::string m_name; public: Element(std::string name) { m_name = name; } std::string getName() { return m_name; } void setName(std::string name) { m_name = name; } };
I've also got another project in the same solution, MyProjectTest, which has MyProject added as a reference and which has one file, MyProjectTest.cpp:
#include "pch.h" #include "CppUnitTest.h" import Model; using namespace Microsoft::VisualStudio::CppUnitTestFramework; namespace GsnEdTest { TEST_CLASS(GsnEdTest) { public: TEST_METHOD(TestAttributeInit) { std::string name = "Test"; Element e(name); Assert::AreEqual(name, e.getName()); } }; }
But compilation of that last file fails because it cannot find the module 'Model'. How do I make it visible?
This title and content for this question was made by "digitig" at this link: https://stackoverflow.com/questions/77385907/how-do-i-import-a-module-from-another-project-within-the-same-visual-studio-solu. Contributions on stackoverflow.com are made under this license.