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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:43:16+00:00 2026-06-12T06:43:16+00:00

I have a Visual C++ solution, which consists out of 3 projects. One of

  • 0

I have a Visual C++ solution, which consists out of 3 projects.

One of these projects, project “A” is used by both other projects and it has some global data which should always be the same.

However when I link project A into both other projects it seems that two instances of project A are working on different data.

Can this be the case and how can I set up the linking process to prevent this from happending?

— Update to make things more clear

- Project 1 -

main () {
  init();
  test();
}

- Project 2 -

test () {
  cout << get_data();
}

- Project A -

int data;

init() {
  data = 123;
}

get_data() {
  return data;
}

As you can see in this exaple I am initializeing the data of project A in the first project and I am accessing it from the second project. My observation is that the data is not initialized when the acces from the second project takes place.

Both projects A and 2 are linked statically into project 1 so the output is a single executable.

  • 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-06-12T06:43:18+00:00Added an answer on June 12, 2026 at 6:43 am

    The symbols from project A in the static library are linked into both project 1 and project 2, separately. Getting them merged involves compiler-specific mechanisms.

    Basically, you must make project 2 re-export project A’s symbols, and have project 1 import those instead of importing project A directly.

    If you can’t do that (e.g. because you don’t have control over either project 1 or 2), you must write workarounds inside project A. One option (the easiest usually) is to convert project A to a dynamic library. Then both project 1 and 2 load the same instance of project A and the data is shared.

    Another option is to change project A so that it doesn’t have a global variable, but instead registers a process-global data item that contains the data you want; for example, you could abuse the local atom table[1] to store a pointer to dynamic memory.

    [1] http://msdn.microsoft.com/en-us/library/windows/desktop/ms649053%28v=vs.85%29.aspx#_win32_Integer_Atoms

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

Sidebar

Related Questions

I have a Visual Studio 2008 solution which consists of some projects and uses
I have a Visual Studio 2008 solution with several projects. One project is a
I have a Visual Studio solution which is open in both blend 2 SP1
I have a Visual C++ solution with 2 projects AlgorithmA & AlgorithmB and both
I have a Visual Studio 2008 solution with two projects (a Word-Template project and
I have a C# solution which has 2 projects in it and I need
We have a Visual Studio 2010 solution that has over 120 projects that reference
I have a Visual Studio 2010 solution with 8 projects. It also has a
I have a Visual Studio solution which consists of a DLL and an EXE.
My windows forms application consists of one Visual Studio solution and several projects. The

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.