I’m using modules with latest CMake and latest MSVC.
Most of this stuff if working nice but I’m having trouble exporting a static constexpr
symbol from my class.
This is my simplified setup
#include <array>
namespace foo
{
class base
{
public:
void foo() {};
constexpr int doSomthingWithArray();
private:
static constexpr std::array m_dummyArray {1u,2u};
}
constexpr int base::doSomthingWithArray()
{
//use m_dummyArray somehow and return some value from array
return 0;
}
}
Now in my C++ module i’m exporting this stuff using
// Global module fragment where #includes can happen
module;
#include "base.hpp"
// first thing after the Global module fragment must be a module command
export module my_module;
export
{
namespace foo
{
using ::foo::base;
}
}
now when i consume this module for example via
#include <gtest/gtest.h>
import my_module;
TEST(Foo,Bar)
{
base instance;
instance.foo(); //< works
base::doSomthingWithArray(); //< produces linker error
}
on the consumer side base::doSomthingWithArray()
produces a linker error undefined external symbol m_dummyArray
I’m guessing that m_dummyArray somehow has an internal linakge.
I did try to force external linakge by adding an export
to m_dummyArray
via
MODULE_EXPORT static constexpr std::array m_dummyArray {1u,2u};
where MODULE_EXPORT only evaluates to export when included in an actual module (and not a regular cpp file) but this produces a compiler error.
Does anybody have an idea on how to fix this?
0