Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 560261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:19:28+00:00 2026-05-13T12:19:28+00:00

I am working on a fairly significantly-sized project which spans many shared libraries. We

  • 0

I am working on a fairly significantly-sized project which spans many shared libraries. We also have significant reliance on the STL, Boost and our own template classes and functions. Many exported classes contain template members and exported functions contain template parameters.

Here is a stripped-down example of how I do library exporting:

#if defined(_MSC_VER) && defined(_DLL)
    //    Microsoft 
    #define EXPORT __declspec(dllexport)
    #define IMPORT __declspec(dllimport)
#elif defined(_GCC)
    //    GCC
    #define EXPORT __attribute__((visibility("default")))
    #define IMPORT
#else
    //    do nothing and hope for the best at link time
    #define EXPORT
    #define IMPORT
#endif

#ifdef _CORE_COMPILATION
#define PUBLIC_CORE EXPORT
#define EXTERNAL_CORE
#else
#define PUBLIC_CORE IMPORT
#define EXTERNAL_CORE extern
#endif

#include <deque>

//    force exporting of templates
EXTERNAL_CORE template class PUBLIC_CORE std::allocator<int>;
EXTERNAL_CORE template class PUBLIC_CORE std::deque<int, std::allocator<int> >;

class PUBLIC_CORE MyObject
{
private:
    std::deque<int> m_deque;
};

SO, my problem is that when I compile in Visual Studio (both 2008 and 2010), I get the following warning:

warning C4251:
‘std::_Deque_val<_Ty,_Alloc>::_Almap’
: class ‘std::allocator<_Ty>’ needs to
have dll-interface to be used by
clients of class
‘std::_Deque_val<_Ty,_Alloc>’

Which seems to imply that I haven’t exported std::allocator<int>, which I have. And it’s not like my exporting is incorrect, since not including

EXTERNAL_CORE template class PUBLIC_CORE std::allocator<int>;
EXTERNAL_CORE template class PUBLIC_CORE std::deque<int, std::allocator<int> >;

yields the warning:

warning C4251: ‘MyObject::m_deque’ :
class ‘std::deque<_Ty>’ needs to have
dll-interface to be used by clients of
class ‘MyObject’

The only thing I can think of is that the _Ty the warning about the std::allocator is talking about is somehow not int, but I can’t seem to find any indication that it would be otherwise, since a std::deque<int> would logically allocate with an std::allocator<int>.

A consuming application can use the class just fine, but I have a gut feeling that this warning should not be ignored. When compiling with g++ in Linux, no errors are emitted (although that doesn’t mean it’s working right). Is g++ automatically doing something that MSVC cannot do? I’ve been targeting GCC on Linux, LLVM on OSX and MSVC on Windows, but I could potentially move to MinGW for Windows development, so abandoning MSVC is not exactly out of the question (if this proves to be too big of an inconvenience).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:19:28+00:00Added an answer on May 13, 2026 at 12:19 pm

    As you may know, the templates in your export file are in fact a ‘permission to fill in whatever you think necessary’ for the compiler.

    That means that if you compile your header file with compiler A, it may instantiate a completely different deque<int> than compiler B. The order of some members may change, for one, or even the actual type of some member variables.

    And that’s what the compiler is warning you for.

    EDIT: addes some consequences to the explanation

    So your shared libraries will only work together nicely when compiled by the same compiler. If you want them to work together, you can either make sure that all client code ‘sees’ the same declaration (through using the same stl implementation), or step back from adding templates to your API.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a fairly complicated project. We have a c# forms app
I am working on a fairly large project and have recently bumped into the
I'm currently working on a project with some fairly significant business rules where the
I'm working on a project which at the moment is unable to have any
I'm working on a fairly convoluted project in which I'm accessing classes written in
I have the following function in access, which was working fairly well. But now
I have a menu working fairly well but can't figure out how to make
I'm working on a fairly large project for a trading company in Philadelphia. The
I'm working on a fairly new project and we started from scratch. So not
I'm working on a fairly large C++ project on Linux. We are trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.