C++20 Module static constexpr class member is not exported

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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#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;
}
}
</code>
<code>#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; } } </code>
#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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>// 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;
}
}
</code>
<code>// 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; } } </code>
// 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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>#include <gtest/gtest.h>
import my_module;
TEST(Foo,Bar)
{
base instance;
instance.foo(); //< works
base::doSomthingWithArray(); //< produces linker error
}
</code>
<code>#include <gtest/gtest.h> import my_module; TEST(Foo,Bar) { base instance; instance.foo(); //< works base::doSomthingWithArray(); //< produces linker error } </code>
#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

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>MODULE_EXPORT static constexpr std::array m_dummyArray {1u,2u};
</code>
<code>MODULE_EXPORT static constexpr std::array m_dummyArray {1u,2u}; </code>
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

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật