inet icon indicating copy to clipboard operation
inet copied to clipboard

MSG compiller didn't add INET_API to some INET classes

Open edlongman opened this issue 5 years ago • 6 comments

I was using the PacketProtocolTag and MacAddressTag from the INET Library.

Having been stuck for ages on why the program woudn't link I inspected the symbols in the .dll and .o files and discovered a symbol mismatch so it wouldn't link to the implementation in the dll.

I then looked through the source code and ProtocolTag_m.h looked like this:

//
// Generated file, do not edit! Created by nedtool 5.6 from inet/common/ProtocolTag.msg.
//

#ifndef __INET_PROTOCOLTAG_M_H
#define __INET_PROTOCOLTAG_M_H

#if defined(__clang__)
#  pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#include <omnetpp.h>

// nedtool version check
#define MSGC_VERSION 0x0506
#if (MSGC_VERSION!=OMNETPP_VERSION)
#    error Version mismatch! Probably this file was generated by an earlier version of nedtool: 'make clean' should help.
#endif


namespace inet {

class ProtocolTagBase;
class DispatchProtocolReq;
class DispatchProtocolInd;
class PacketProtocolTag;
class TransportProtocolReq;
class TransportProtocolInd;
class NetworkProtocolReq;
class NetworkProtocolInd;
class MacProtocolReq;
class MacProtocolInd;
} // namespace inet

#include "inet/common/INETDefs_m.h" // import inet.common.INETDefs

#include "inet/common/Protocol_m.h" // import inet.common.Protocol

#include "inet/common/TagBase_m.h" // import inet.common.TagBase

#include "inet/common/packet/chunk/Chunk_m.h" // import inet.common.packet.chunk.Chunk


namespace inet {

// cplusplus {{
typedef Ptr<const Chunk> ChunkPtr;
// }}

/**
 * Class generated from <tt>inet/common/ProtocolTag.msg:27</tt> by nedtool.
 * <pre>
 * //
 * // This is an abstract base class that should not be directly added as a tag.
 * //
 * class ProtocolTagBase extends TagBase
 * {
 *     const Protocol *protocol \@toString("->str()") = nullptr; // specifies a protocol (internal class with an artificial identifier)
 * }
 * </pre>
 */
class ProtocolTagBase : public ::inet::TagBase
{
  protected:
    const Protocol * protocol = nullptr;

  private:

etc............

When it should have looked like this:

//
// Generated file, do not edit! Created by nedtool 5.6 from inet/common/ProtocolTag.msg.
//

#ifndef __INET_PROTOCOLTAG_M_H
#define __INET_PROTOCOLTAG_M_H

#if defined(__clang__)
#  pragma clang diagnostic ignored "-Wreserved-id-macro"
#endif
#include <omnetpp.h>

// nedtool version check
#define MSGC_VERSION 0x0506
#if (MSGC_VERSION!=OMNETPP_VERSION)
#    error Version mismatch! Probably this file was generated by an earlier version of nedtool: 'make clean' should help.
#endif

// dll export symbol
#ifndef INET_API
#  if defined(INET_EXPORT)
#    define INET_API  OPP_DLLEXPORT
#  elif defined(INET_IMPORT)
#    define INET_API  OPP_DLLIMPORT
#  else
#    define INET_API
#  endif
#endif


namespace inet {

class ProtocolTagBase;
class DispatchProtocolReq;
class DispatchProtocolInd;
class PacketProtocolTag;
class TransportProtocolReq;
class TransportProtocolInd;
class NetworkProtocolReq;
class NetworkProtocolInd;
class MacProtocolReq;
class MacProtocolInd;
} // namespace inet

#include "inet/common/INETDefs_m.h" // import inet.common.INETDefs

#include "inet/common/Protocol_m.h" // import inet.common.Protocol

#include "inet/common/TagBase_m.h" // import inet.common.TagBase

#include "inet/common/packet/chunk/Chunk_m.h" // import inet.common.packet.chunk.Chunk


namespace inet {

// cplusplus {{
typedef Ptr<const Chunk> ChunkPtr;
// }}

/**
 * Class generated from <tt>inet/common/ProtocolTag.msg:27</tt> by nedtool.
 * <pre>
 * //
 * // This is an abstract base class that should not be directly added as a tag.
 * //
 * class ProtocolTagBase extends TagBase
 * {
 *     const Protocol *protocol \@toString("->str()") = nullptr; // specifies a protocol (internal class with an artificial identifier)
 * }
 * </pre>
 */
class INET_API ProtocolTagBase : public ::inet::TagBase
{
  protected:
    const Protocol * protocol = nullptr;

  private:

etc............

Deleting the _m.h file and recompilling the library fixed this but I have no idea how it could have been wrong in the first place.

The Only two files I could see to have missing INET_API definitions were TagBase and PacketProtocolTag, I used MacAddressReq from MacAddressTag.msg with no issues Why was this? Is there something deeper going on?

edlongman avatar Nov 05 '20 10:11 edlongman

I don't know but in my INET all of those MSG generated classes have the INET_API qualifier.

levy avatar Nov 05 '20 10:11 levy

So, it happened again when the rebuild happened. Having looked through the log I'm considering if it is related to multithreaded building of .msg, _m.h and _m.cc files since the only files that are missing the class attributes are the ones compilled immediately following INETDefs that could potentially be compilled in parallel.

I'm not sure exactly what conditions cause the confusion for the message compiler or for the make system in general. What could I use to test it? I've tried deleting all _m.h, _m.cc, _m.h.d files but that didn't replicate the error. I'd like to get it sorted because each time it breaks every dependancy of INETDefs_m.h gets rebuilt, which is all of INET!

Another thing I noticed was different after recompiling. All the msg files have subtly different creation paths (as seen from diff)

INETDefs_m difference `../../inet/src/inet/common/INETDefs.msg` => `./inet/common/INETDefs.msg`
diff --git a/src/inet/common/INETDefs_m.cc b/src/inet/common/INETDefs_m.cc
index 4e07e8b..8fd76b7 100644
--- a/src/inet/common/INETDefs_m.cc
+++ b/src/inet/common/INETDefs_m.cc
@@ -1,5 +1,5 @@
 //
-// Generated file, do not edit! Created by nedtool 5.6 from ../../inet/src/inet/common/INETDefs.msg
+// Generated file, do not edit! Created by nedtool 5.6 from ./inet/common/INETDefs.msg.
 //

 // Disable warnings about unused variables, empty switch stmts, etc:
diff --git a/src/inet/common/INETDefs_m.h b/src/inet/common/INETDefs_m.h
index 52e8243..b2a0210 100644
--- a/src/inet/common/INETDefs_m.h
+++ b/src/inet/common/INETDefs_m.h
@@ -1,5 +1,5 @@
 //
-// Generated file, do not edit! Created by nedtool 5.6 from ../../inet/src/inet/common/INETDefs.msg.
+// Generated file, do not edit! Created by nedtool 5.6 from ./inet/common/INETDefs.msg.
 //

diff --git a/src/inet/common/ProtocolTag_m.cc b/src/inet/common/ProtocolTag_m.cc
index 262e436..b17321b 100644
--- a/src/inet/common/ProtocolTag_m.cc
+++ b/src/inet/common/ProtocolTag_m.cc
@@ -1,5 +1,5 @@
 //
-// Generated file, do not edit! Created by nedtool 5.6 from ../../inet/src/inet/common/ProtocolTag.msg.
+// Generated file, do not edit! Created by nedtool 5.6 from inet/common/ProtocolTag.msg.
 //

 // Disable warnings about unused variables, empty switch stmts, etc:
diff --git a/src/inet/common/ProtocolTag_m.h b/src/inet/common/ProtocolTag_m.h
index cfb9073..a97084d 100644
--- a/src/inet/common/ProtocolTag_m.h
+++ b/src/inet/common/ProtocolTag_m.h
@@ -1,5 +1,5 @@
 //
-// Generated file, do not edit! Created by nedtool 5.6 from ../../inet/src/inet/common/ProtocolTag.msg.
+// Generated file, do not edit! Created by nedtool 5.6 from inet/common/ProtocolTag.msg.
 //

edlongman avatar Nov 13 '20 10:11 edlongman

@edlongman I'm trying to replicate this. How do you generate the two versions. One is parallel the other is sequential build? Or what is the exact difference? It is not clear from your description.

rhornig avatar Nov 13 '20 12:11 rhornig

It is just an automatic build in the eclipse IDE from running a project with inet as a referenced project.

They are both parallel build.

The command run is a normal make MODE=DEBUG -j8 There is no difference, but simply deleting the _m.h files means that second time around it has built correctly.

On Fri, 13 Nov 2020, 12:15 Rudolf Hornig, [email protected] wrote:

@edlongman https://github.com/edlongman I'm trying to replicate this. How do you generate the two versions. One is parallel the other is sequential build? Or what is the exact difference? It is not clear from your description.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/inet-framework/inet/issues/571#issuecomment-726732408, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFJJUFLQRVSZ6Q3BBQT66LSPUPMVANCNFSM4TLEWJEA .

edlongman avatar Nov 13 '20 13:11 edlongman

This is for OMNEt 5.6 which is quite old. With omnet 5.7 and 6.0 I cannot reproduce this, however you must be sure that -pINET is used at the opp_makemake command line. That option forces the messgae compiler to add the INET_API macros.

rhornig avatar May 13 '22 18:05 rhornig

I have upgraded to OMNET 6.0 and INET 4.4 and rebuilt from scratch and I had the same issue with "PacketProtocolTag" - "lld-link: error: undefined symbol"

It's also happening with TlvOptions and TlvOptionBase

edlongman avatar Jun 14 '22 10:06 edlongman

I have tested this again with INET 4.4 and cannot reproduce this. If you can reliably reproduce this issue, please reopen this and provide additional info.

rhornig avatar Mar 13 '23 10:03 rhornig