Skip to content

Commit 431770d

Browse files
Fix Windows DLL link errors: force instantiation of Ref<string> adapters
StringRef, ConstStringRef, and ConstStringListRef are exported (FTXUI_EXPORT(SCREEN)), but every one of their member functions -- including ones inherited from Ref<string>/ConstRef<string> -- is defined inline in the header and never odr-used from within libftxui-screen itself. MSVC only emits (and therefore dllexports) an inline member function into the DLL that first odr-uses it, so consumers linking against the dllimport declaration got LNK2001 unresolved externals. Add ref.cpp to the screen library across all build systems (CMake, Bazel, Meson) with a throwaway function that exercises every member, forcing MSVC to instantiate and export them.
1 parent 686e908 commit 431770d

4 files changed

Lines changed: 53 additions & 0 deletions

File tree

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ftxui_cc_library(
4545
"src/ftxui/screen/string_internal.hpp",
4646
"src/ftxui/screen/terminal.cpp",
4747
"src/ftxui/screen/util.hpp",
48+
"src/ftxui/util/ref.cpp",
4849
],
4950
hdrs = [
5051
"include/ftxui/screen/box.hpp",

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ add_library(screen
4949
include/ftxui/screen/string.hpp
5050
include/ftxui/screen/surface.hpp
5151
include/ftxui/util/export.hpp
52+
include/ftxui/util/ref.hpp
53+
src/ftxui/util/ref.cpp
5254
src/ftxui/screen/box.cpp
5355
src/ftxui/screen/color.cpp
5456
src/ftxui/screen/color_info.cpp

src/ftxui/screen/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ screen_sources = files(
66
'screen.cpp',
77
'string.cpp',
88
'terminal.cpp',
9+
'../util/ref.cpp',
910
)

src/ftxui/util/ref.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2026 Arthur Sonzogni. All rights reserved.
2+
// Use of this source code is governed by the MIT license that can be found in
3+
// the LICENSE file.
4+
#include "ftxui/util/ref.hpp"
5+
6+
#include <utility>
7+
8+
namespace ftxui {
9+
10+
namespace {
11+
12+
// StringRef, ConstStringRef, and ConstStringListRef are exported
13+
// (FTXUI_EXPORT(SCREEN)), but all of their member functions -- including
14+
// ones inherited from Ref<string>/ConstRef<string> -- are defined inline in
15+
// the header and never odr-used from within libftxui-screen itself. On
16+
// Windows, MSVC only emits (and therefore dllexports) an inline member
17+
// function into the DLL that first odr-uses it; otherwise consumers linking
18+
// against the dllimport declaration get an unresolved external symbol. This
19+
// function exists solely to force that instantiation.
20+
[[maybe_unused]] void ForceSymbolInstantiation() {
21+
StringRef s = "a";
22+
StringRef s2(s);
23+
StringRef s3(std::move(s2));
24+
s = s3;
25+
s = std::move(s3);
26+
(void)s();
27+
(void)*s;
28+
(void)s.operator->();
29+
30+
ConstStringRef c = "a";
31+
ConstStringRef c2(c);
32+
ConstStringRef c3(std::move(c2));
33+
c = c3;
34+
c = std::move(c3);
35+
(void)c();
36+
(void)*c;
37+
38+
ConstStringListRef l;
39+
ConstStringListRef l2(l);
40+
ConstStringListRef l3(std::move(l2));
41+
l = l3;
42+
l = std::move(l3);
43+
(void)l.size();
44+
(void)l[0];
45+
}
46+
47+
} // namespace
48+
49+
} // namespace ftxui

0 commit comments

Comments
 (0)