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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:37:56+00:00 2026-05-10T15:37:56+00:00

I have a static library written in C++ and I have a structure describing

  • 0

I have a static library written in C++ and I have a structure describing data format, i.e.

struct Format{     long fmtId;     long dataChunkSize;     long headerSize;      Format(long, long, long);      bool operator==(Format const & other) const; }; 

Some of data formats are widely used, like {fmtId=0, dataChunkSize=128, headerSize=0} and {fmtId=0, dataChunkSize=256, headerSize=0}

Some data structure classes receive format in constructor. I’d like to have some sort of shortcuts for those widely used formats, like a couple of global Format members gFmt128, gFmt256 that I can pass by reference. I instantiate them in a .cpp file like

Format gFmt128(0, 128, 0);

and in .h there is

extern Format gFmt128;

also, I declare Format const & Format::Fmt128(){return gFmt128;} and try to use it in the main module.

But if I try and do it in the main module that uses the lib, the linker complains about unresolved external gFmt128.

How can I make my library ‘export’ those global vars, so I can use them from other modules?

  • 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. 2026-05-10T15:37:57+00:00Added an answer on May 10, 2026 at 3:37 pm

    Don’t use the static keyword on global declarations. Here is an article explain the visibility of variables with/without static. The static gives globals internal linkage, that is, only visible in the translation unit they are declared in.

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

Sidebar

Related Questions

I have written a static library to re-use some code between iOS projects, let's
I have a static library (let's call it S) that uses a category (NSData+Base64
I have created a static library following this link . But I am facing
I have a static C library (say mylib.a ) and I was wondering if
i have made my custom Static Library (.a) successfully. i have tested it in
I have an Xcode project with several static library dependancies set up in the
I was given an static library (.a extension file) that I have to use
I have refactored some UIView sub-classes into a static library. However, when using Interface
I have some code shared among multiple projects in a static library. Even with
I have a Visual Studio 2008 C++ project that outputs a static library and

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.