admin管理员组

文章数量:1125037

A proprietary closed-source 3rd-party library which is central to our legacy codebase has define _System in one of its headers.

This is causing a problem because another library we use () indirectly has dependencies on the Windows concurrency runtime.

Which leads us to concrt.h:

enum _Type
{
    /// <summary>
    ///     Indicates that the location represents the "system location". This has no specific affinity.
    /// </summary>
    _System, // _M_id is meaningless

    /// <summary>
    ///     Indicates that the location represents a particular NUMA node.
    /// </summary>
    _NumaNode, // _M_id is the Windows NUMA node number

    /// <summary>
    ///     Indicates that the location represents a particular scheduling node.
    /// </summary>
    _SchedulingNode, // _M_id is the unique identifier for the scheduling node

    /// <summary>
    ///     Indicates that the location represents a particular execution resource.
    /// </summary>
    _ExecutionResource, // _M_id is the unique identifier for the execution resource
};

This can't be a totally uncommon problem, are there any obvious workarounds or are we effectively stuck (apart from changing/replacing one of the libraries?)

A proprietary closed-source 3rd-party library which is central to our legacy codebase has define _System in one of its headers.

This is causing a problem because another library we use (https://github.com/microsoft/cpprestsdk) indirectly has dependencies on the Windows concurrency runtime.

Which leads us to concrt.h:

enum _Type
{
    /// <summary>
    ///     Indicates that the location represents the "system location". This has no specific affinity.
    /// </summary>
    _System, // _M_id is meaningless

    /// <summary>
    ///     Indicates that the location represents a particular NUMA node.
    /// </summary>
    _NumaNode, // _M_id is the Windows NUMA node number

    /// <summary>
    ///     Indicates that the location represents a particular scheduling node.
    /// </summary>
    _SchedulingNode, // _M_id is the unique identifier for the scheduling node

    /// <summary>
    ///     Indicates that the location represents a particular execution resource.
    /// </summary>
    _ExecutionResource, // _M_id is the unique identifier for the execution resource
};

This can't be a totally uncommon problem, are there any obvious workarounds or are we effectively stuck (apart from changing/replacing one of the libraries?)

Share Improve this question edited 2 days ago 3CxEZiVlQ 37.7k10 gold badges70 silver badges88 bronze badges asked 2 days ago Mr. BoyMr. Boy 63.7k100 gold badges349 silver badges643 bronze badges 4
  • 1 You need to talk to your library supplier as "identifiers that appear as a token or preprocessing token ... are reserved ... * in the global namespace, identifiers that begin with an underscore" en.cppreference.com/w/cpp/language/identifiers – Richard Critten Commented 2 days ago
  • @RichardCritten well we should but it could take a long time, and then if they release a new version it could take a long time for it to be verified for production use. So it's not really a viable option in the available timeframe – Mr. Boy Commented 2 days ago
  • 4 How about #undef ? – Richard Critten Commented 2 days ago
  • Adapt either(both) library into a local wrapper codebase and don't expose the adapted headers. Provide a namespace for each library and avoid using macros in public headers(except for compile flow management). Use strict naming conventions. – Red.Wave Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 1

Separation of code a) that's using the 3rd party library b) that's using cpprestsdk into different compilation units should solve the problem.

本文标签: cA 3rd party library defines a symbol clashing with a WinAPI definitionStack Overflow