Skip to content

Commit a682a4a

Browse files
committed
#537 Fixed the Windows DLL build by exporting message::EMPTY_STR and message::EMPTY_BIN
1 parent 01a30cf commit a682a4a

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ All notable changes to this project will be documented in this file.
66

77
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
88

9+
## Upcoming Version 1.5.2 (unreleased)
10+
11+
- [#537](https://github.com/eclipse-paho/paho.mqtt.cpp/issues/537) Fixed the Windows DLL build by exporting message::EMPTY_STR and message::EMPTY_BIN
12+
13+
914

1015
## [Version 1.5.1](https://github.com/eclipse/paho.mqtt.cpp/compare/v1.5.0..v1.5.1) - (2025-02-09)
1116

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ if(NOT PAHO_BUILD_SHARED AND NOT PAHO_BUILD_STATIC)
4949
message(FATAL_ERROR "You must set either PAHO_BUILD_SHARED, PAHO_BUILD_STATIC, or both")
5050
endif()
5151

52+
# --- Setting naming variables ---
53+
54+
set(PAHO_MQTTPP_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR}/generated)
55+
5256
## --- Find Paho C or build it, if reqested ---
5357

5458
if(PAHO_WITH_SSL)
@@ -137,6 +141,15 @@ if(PAHO_BUILD_TESTS)
137141
add_subdirectory(test/unit)
138142
endif()
139143

144+
## --- Install generated header(s) ---
145+
146+
install(
147+
DIRECTORY
148+
${PAHO_MQTTPP_GENERATED_DIR}/include/
149+
DESTINATION
150+
${CMAKE_INSTALL_INCLUDEDIR}
151+
)
152+
140153
## --- Packaging settings ---
141154

142155
if(WIN32)

include/mqtt/message.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class message
6565
/** Initializer for the C struct (from the C library) */
6666
static constexpr MQTTAsync_message DFLT_C_STRUCT MQTTAsync_message_initializer;
6767
/** A const string to use for references */
68-
static const string EMPTY_STR;
68+
PAHO_MQTTPP_EXPORT static const string EMPTY_STR;
6969
/** A const binary to use for references */
70-
static const binary EMPTY_BIN;
70+
PAHO_MQTTPP_EXPORT static const binary EMPTY_BIN;
7171

7272
/** The underlying C message struct */
7373
MQTTAsync_message msg_{DFLT_C_STRUCT};

src/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
set (THREADS_PREFER_PTHREAD_FLAG ON)
2929
find_package(Threads REQUIRED)
3030

31+
include(GenerateExportHeader)
32+
3133
## --- Use object library to optimize compilation ---
3234

3335
set(COMMON_SRC
@@ -77,6 +79,11 @@ if(PAHO_BUILD_SHARED)
7779
VERSION ${PROJECT_VERSION}
7880
SOVERSION ${PROJECT_VERSION_MAJOR}
7981
)
82+
83+
generate_export_header(paho-mqttpp3-shared
84+
BASE_NAME paho_mqttpp
85+
EXPORT_FILE_NAME ${PAHO_MQTTPP_GENERATED_DIR}/include/mqtt/export.h
86+
)
8087
endif()
8188

8289
## --- Build static version of the library, if requested ---
@@ -99,9 +106,15 @@ if(PAHO_BUILD_STATIC)
99106
if(${PAHO_BUILD_SHARED})
100107
# This lib should configure for static exports
101108
target_compile_definitions(paho-mqttpp3-static PRIVATE PAHO_MQTTPP_STATIC)
109+
target_compile_definitions(paho-mqttpp3-static PRIVATE PAHO_MQTTPP_STATIC_DEFINE)
102110
else()
103111
# If no shared lib, make this one the default target
104112
add_library(PahoMqttCpp::paho-mqttpp3 ALIAS paho-mqttpp3-static)
113+
114+
generate_export_header(paho-mqttpp3-static
115+
BASE_NAME paho_mqttpp
116+
EXPORT_FILE_NAME ${PAHO_MQTTPP_GENERATED_DIR}/include/mqtt/export.h
117+
)
105118
endif()
106119

107120
## Let the archive use the same base name as the shared lib on *nix systems
@@ -110,6 +123,12 @@ if(PAHO_BUILD_STATIC)
110123
endif()
111124
endif()
112125

126+
## --- Make sure at least one target was specified ---
127+
128+
if(NOT PAHO_CPP_TARGETS)
129+
message(FATAL_ERROR "No build targets are specified")
130+
endif()
131+
113132
## --- Set common properties, etc ---
114133

115134
include(GNUInstallDirs)

src/message.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
*******************************************************************************/
1818

1919
#include "mqtt/message.h"
20+
#include "mqtt/export.h"
2021

2122
#include <cstring>
2223
#include <utility>
2324

2425
namespace mqtt {
2526

2627
// A const string to use for references
27-
const string message::EMPTY_STR;
28+
PAHO_MQTTPP_EXPORT const string message::EMPTY_STR;
2829

2930
// A const binary to use for references
30-
const binary message::EMPTY_BIN;
31+
PAHO_MQTTPP_EXPORT const binary message::EMPTY_BIN;
3132

3233
/////////////////////////////////////////////////////////////////////////////
3334

0 commit comments

Comments
 (0)