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 6137429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:43:29+00:00 2026-05-23T17:43:29+00:00

I want to write a (static) library for other programmers to use that uses

  • 0

I want to write a (static) library for other programmers to use that uses the compiler’s optimisations.

Whilst writing and testing the library using debug builds I find it runs quite slowly, but if I switch to a release build then it seems to be acceptably fast.

At the moment I’ve compiled the library as a debug build and I’m using it in another project and I notice how slowly it runs, but if I try to switch my new project to a release build, then the link fails with lots of errors like this:

LIBCMTD.lib(tzset.obj) : error LNK2005: __tzset already defined in MSVCRT.lib(MSVCR90.dll)

What settings should I use when building my library so that programmers can use the library in their own projects so it runs acceptably quickly whether they use debug or release builds?

  • 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-23T17:43:30+00:00Added an answer on May 23, 2026 at 5:43 pm

    This is the old problem of static libraries: it has to use the same CRT of the executable that links against it, otherwise the linker will find conflicting versions of the same CRT routines and data structures (both the public and the internal ones).

    Since there are currently 4 versions of the CRT (all the debug/release and dll/static link combinations), you should provide 4 different .lib files of your library. Incidentally, this is one of the reasons why almost nobody distributes static libraries in .lib form (unless they are just import libraries), but provide the sources to be compiled in any way the library user prefers.

    If you don’t like this, you should consider distributing your library as a dll. In this last case, you still must be careful about the CRT, because if the dll and the program that uses it do not share the same CRT (e.g. one of them uses the static-linking version of the CRT, or they use different versions of the dynamic-linking CRT) you cannot rely on several C++ facilities to work correctly; the most evident problem is that you cannot delete stuff that was allocated with new by the other module, because the two CRTs are using two separated heaps.

    Also, trying to pass types defined in the C++ library across the modules will probably result in problems, because nothing guarantees that they are binary compatible across different CRT versions (and often they won’t). RTTI and exceptions are also problematic areas if you mismatch CRTs.

    Long story short: with static libraries, you must match the CRTs, otherwise the various modules won’t link together. With dlls, match correctly the CRTs and everything should work fine. Otherwise, the only wise alternative is to provide a C-style interface and let each module manage its memory allocations (perhaps exporting its malloc/free to let other modules allocate/free the memory from the module’s heap).

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

Sidebar

Related Questions

I want to write a class library that works in ASP.NET and standalone applications.
Recently I found a C library that I want to use in my C++
I want to write an extension method for a collection of objects that uses
I want to write a command that specifies the word under the cursor in
I want to write a function in Python that returns different fixed values based
I want to write a function that takes an array of letters as an
I want to write a word addin that does some computations and updates some
I want to write some JavaScript that will change the onmousedown of a div
I want to write something that acts just like confirm() in javascript, but I
I want to resize an image with the GDI library so that when I

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.