Link Error: DoS_tests.cpp is failing build (Type mismatch) #4948

issue ENikS opened this issue on September 19, 2014
  1. ENikS commented at 11:49 PM on September 19, 2014: contributor

    In main.cpp c362c57 mapOrphanTransactions was redefined:

    From:

    map<uint256, CTransaction> mapOrphanTransactions;
    

    To:

    struct COrphanTx {
        CTransaction tx;
        NodeId fromPeer;
    };
    map<uint256, COrphanTx> mapOrphanTransactions;
    

    This change breaks build of DoS_tests.cpp where mapOrphanTransactions is referred to as:

    extern std::map<uint256, CTransaction> mapOrphanTransactions
    

    Although it works and links on MinGW, MSVC refuses to link.

  2. theuni commented at 2:58 AM on September 20, 2014: member

    ping @gavinandresen . This came from the movement in c74332c67806ed92e6e18de174671a7c30608780 . I suppose just updating the extern is the way to go until someone decides to start slashing globals.

  3. sipa commented at 2:59 AM on September 20, 2014: member

    We should just change the extern definition in DoS_tests.cpp.

  4. ENikS commented at 3:41 AM on September 20, 2014: contributor

    Would it be more elegant to inherit COrphanTx from CTransaction?

  5. laanwj commented at 7:40 AM on September 20, 2014: member

    @ENikS That depends on whether you see COrphanTx as a helper structure that contains a transaction and a peer id, or as a 'kind of' transaction. I tend to lean towards the first definition as there is nothing inherent to the concept of orphan transactions that would imply they contain a peer ID (although the COrphanTx name indeed puts you on the wrong track) and here prefer composition to subclassing.

  6. laanwj commented at 7:55 AM on September 20, 2014: member

    See #4950

  7. ENikS commented at 8:12 PM on September 20, 2014: contributor

    What makes me wander is why linker allows this strange polymorphism in the first place?

  8. sipa commented at 8:22 PM on September 20, 2014: member

    I don't think the return type must necessarily be part of the resulting symbol, as you can't have multiple definitions that only differ by return type.

  9. ENikS commented at 8:58 PM on September 20, 2014: contributor

    You lost me there, what return type are you talking about? I was referring to definitions:

    map<uint256, CTransaction> mapOrphanTransactions; 
    vs
    map<uint256, COrphanTx> mapOrphanTransactions
    
  10. sipa commented at 9:42 PM on September 20, 2014: member

    Sorry, value type here. It's not possible to have two mapOrphanTransaction definitions with a different type, so there's no requirement for them to be a different symbol.

    In the case of functions, it is possible to have different definitions if the argument types are different, but not if only the return type differs.

  11. ENikS commented at 10:05 PM on September 20, 2014: contributor

    It still doesn't answer my question why wasn't it captured by build tester but it is not critical as long as it is fixed.

  12. sipa commented at 10:13 PM on September 20, 2014: member

    The linker allows it because it doesn't know or care that it is wrong. It would only notice if the symbol name includes the type - which is what presumably happens in MSVC but not in MingW.

  13. ENikS commented at 12:19 AM on September 21, 2014: contributor

    Got it now. Yes, indeed. MS uses type related names so these two are different in linker's view.

  14. laanwj commented at 7:34 PM on September 21, 2014: member

    Fixed by #4950

  15. laanwj closed this on Sep 21, 2014

  16. MarcoFalke locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-18 21:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me