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

  • Home
  • SEARCH
  • 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 630377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:50:54+00:00 2026-05-13T19:50:54+00:00

What is the difference/relationship between extern and __declspec(dllimport) ? I found that sometimes it

  • 0

What is the difference/relationship between extern and __declspec(dllimport)? I found that sometimes it is necessary to use both of them, sometimes one is enough.

Am I right that:

  1. extern is for statically linked libraries,
  2. __declspec(dllimport) is for DLL (dynamically linked libraries),
  3. both do actually the same job for their respective type of linking,
  4. you need to use both when you use import libraries (small .lib files that help linking with dll)?
  • 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-13T19:50:55+00:00Added an answer on May 13, 2026 at 7:50 pm

    extern means that the entity has external linkage, i.e. is visible outside its translation unit (C or CPP file). The implication of this is that a corresponding symbol will be placed in the object file, and it will hence also be visible if this object file is made part of a static library. However, extern does not by itself imply that the symbol will also be visible once the object file is made part of a DLL.

    __declspec(dllexport) means that the symbol should be exported from a DLL (if it is indeed made part of a DLL). It is used when compiling the code that goes into the DLL.

    __declspec(dllimport) means that the symbol will be imported from a DLL. It is used when compiling the code that uses the DLL.

    Because the same header file is usually used both when compiling the DLL itself as well as the client code that will use the DLL, it is customary to define a macro that resolves to __declspec(dllexport) when compiling the DLL and __declspec(dllimport) when compiling its client, like so:

    #if COMPILING_THE_DLL
        #define DLLEXTERN __declspec(dllexport)
    #else
        #define DLLEXTERN __declspec(dllimport)
    #endif
    

    To answer your specific questions:

    1. Yes, extern alone is sufficient for static libraries.
    2. Yes — and the declaration also needs an extern (see explanation here).
    3. Not quite — see above.
    4. You don’t strictly need the extern with a __declspec(dllimport) (see explanation linked to above), but since you’ll usually be using the same header file, you’ll already have the extern in there because it’s needed when compiling the DLL.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 446k
  • Answers 446k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I added character encodings to my sitemap to italicize. Ex:… May 15, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer When sending the mail via SMTP you supply the FROM… May 15, 2026 at 7:08 pm
  • Editorial Team
    Editorial Team added an answer Sorry - I'm using SSRS 2005, no option to define… May 15, 2026 at 7:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.