Hello everyone,
I am currently working on a test-project where I want to use shared libraries and I would like to leverage the new C++20 modules feature. However, I am having some difficulty understanding how to properly set up my code to use C++20 modules between these shared libraries.
I have already set my compiler to use the C++20 standard, but I am unsure of the changes I need to make in my code and build system to use modules with shared libraries.
// test.modules.ixx
export module test.modules;
export void myFunction();
export class Test
{
public:
Test();
};
// test.modules.cpp
module;
#include <iostream>
module test.modules;
void myFunction()
{
std::cout << "hello from module";
}
Test::Test()
{
std::cout << "init";
}
Command line options
/JMC /experimental:module /permissive- /ifcOutput "x64\Debug\" /GS /W3 /Zc:wchar_t /ZI /Gm- /Od /sdl /Fd"x64\Debug\vc143.pdb" /Zc:inline /fp:precise /D "_DEBUG" /D "TESTLIB_EXPORTS" /D "_WINDOWS" /D "_USRDLL" /D "MATHLIBRARY_EXPORTS" /D "_WINDLL" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++latest /FC /Fa"x64\Debug\" /EHsc /nologo /Fo"x64\Debug\" /Fp"x64\Debug\testLib.pch" /diagnostics:column
When importing this into another project i get following errors:
// My Executable
import test.modules;
int main()
{
std::cout << "Hello World!\n";
myFunction();
Test();
}
error C2230: could not find module 'test.modules'
error C3861: 'myFunction': identifier not found
error C3861: 'Test': identifier not found
Here are some specific questions I have:
- How should I structure my code to define and import modules in different shared libraries?
- Are there any specific compiler flags I need to use to enable modules?
- Are there any known issues or limitations I should be aware of when using C++20 modules with shared libraries?
Any examples, resources, or advice would be greatly appreciated. Thank you in advance for your help!
Thanks