Skip to content

Commit 15b6b90

Browse files
committed
common: fix: export CodeFragment/SharedDataManager with INET_API (Windows link error)
On Windows/MinGW, linking a project against INET's shared library failed to resolve symbols defined in Compat.h -- e.g. CodeFragment's constructor, which backs Register_Serializer and the other EXECUTE_* / Define_InitStage macros -- because the OMNETPP_BUILDNUM<2000 compat classes CodeFragment and SharedDataManager were declared without INET_API and so were never dllexported. Simply adding INET_API to the two classes does not compile, because INETDefs.h included Compat.h before defining INET_API (the macro was an undefined token at the declarations). Fix the ordering: move the Compat.h/ParsimPacking.h includes below the INET_API definition in INETDefs.h, and make the two files that included Compat.h directly (Compat.cc, QueueVisualizerBase.h) include INETDefs.h instead. Add a guard to Compat.h that rejects direct inclusion with a clear error, since it uses INET_API but does not define it. No effect on non-Windows builds (INET_API is empty there). Verified by a full release build. Fixes #1108.
1 parent c5dff26 commit 15b6b90

4 files changed

Lines changed: 17 additions & 7 deletions

File tree

src/inet/common/Compat.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66

77

8-
#include "inet/common/Compat.h"
8+
#include "inet/common/INETDefs.h" // pulls in Compat.h after INET_API is defined
99

1010
namespace inet {
1111

src/inet/common/Compat.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
#ifndef __INET_COMPAT_H
99
#define __INET_COMPAT_H
1010

11+
// This is an internal compatibility shim: it declares INET_API-exported classes
12+
// but relies on INETDefs.h to define INET_API beforehand. It must therefore be
13+
// reached only through inet/common/INETDefs.h, never included directly.
14+
#ifndef __INET_INETDEFS_H
15+
#error "Do not include inet/common/Compat.h directly; include inet/common/INETDefs.h instead."
16+
#endif
17+
1118
#include <omnetpp.h>
1219

1320
#include <functional>
@@ -39,7 +46,7 @@ typedef int sharedcounterhandle_t;
3946
* This class encapsulates the "simulation-global variables" functionality which became
4047
* part of the cSimulation class in OMNeT++ 7.0.
4148
*/
42-
class SharedDataManager : public omnetpp::cISimulationLifecycleListener
49+
class INET_API SharedDataManager : public omnetpp::cISimulationLifecycleListener
4350
{
4451
private:
4552
struct SharedDataHandles {
@@ -186,7 +193,7 @@ T& SharedDataManager::getSharedVariable(int handle, Args&&... args)
186193
* Supporting class for EXECUTE_PRE_NETWORK_SETUP() / EXECUTE_POST_NETWORK_DELETE(),
187194
* which didn't exist prior to OMNeT++ 7.0.
188195
*/
189-
class CodeFragment
196+
class INET_API CodeFragment
190197
{
191198
private:
192199
omnetpp::SimulationLifecycleEventType lifecycleEvent;

src/inet/common/INETDefs.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
// General definitions.
2626
//
2727

28-
#include "inet/common/Compat.h"
29-
#include "inet/common/ParsimPacking.h"
30-
3128
namespace inet {
3229
using namespace omnetpp;
3330
using omnetpp::operator<<;
@@ -48,6 +45,12 @@ using omnetpp::operator<<;
4845
#define INET_API
4946
#endif // if defined(INET_EXPORT)
5047

48+
// Compat.h declares exported classes (e.g. CodeFragment) using INET_API, so it
49+
// must be included only after INET_API is defined above. ParsimPacking.h is
50+
// kept alongside it.
51+
#include "inet/common/Compat.h"
52+
#include "inet/common/ParsimPacking.h"
53+
5154
#include "inet/common/InitStages.h"
5255

5356
#ifndef SIMTIME_RAW_T_DEFINED

src/inet/visualizer/base/QueueVisualizerBase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#ifndef __INET_QUEUEVISUALIZERBASE_H
99
#define __INET_QUEUEVISUALIZERBASE_H
1010

11-
#include "inet/common/Compat.h"
11+
#include "inet/common/INETDefs.h"
1212
#include "inet/queueing/contract/IPacketQueue.h"
1313
#include "inet/visualizer/base/VisualizerBase.h"
1414
#include "inet/visualizer/util/Placement.h"

0 commit comments

Comments
 (0)