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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T09:24:48+00:00 2026-05-19T09:24:48+00:00

I used to have a static library which was imported by both my main

  • 0

I used to have a static library which was imported by both my main program and my tests. However, I needed global variables inside of my static library to be constructed, and there’s no way to force Visual Studio to do that.

What I’d like to do then is to have a project which compiles all the common C++ files, a project which compiles and links the unit tests (with the common C++ files), and a project which links the actual application.

How can I do this in Visual Studio 2010?

EDIT: Because clarification has been asked, here’s what I mean:

InterfaceIUse.hpp

#include <memory>

struct IInterface
{
    virtual ~IInterface() {}
    virtual void SomethingIDependOn() = 0;
};

std::auto_ptr<IInterface> FactoryMethod();

CodeUnderTest.cpp

#include "InterfaceIUse.hpp"

void FunctionUnderTest()
{
    //Blah blah blah
}

IExistOnlyInTheMainProgram.cpp

#include "InterfaceIUse.hpp"

std::auto_ptr<IInterface> FactoryMethod()
{
    //I return the real implementation of the interface.
}

IExistOnlyInTheTest.cpp

#include "InterfaceIUse.hpp"

std::auto_ptr<IInterface> FactoryMethod()
{
    //I return the mock implementation of the interface.
}

The idea is to compile the right .cpp implementation of the given factory, which will allow the dependencies of the code to be tested to be dependency injected.

Doing this kind of link seam is easy with makefiles — but makefiles are undesirable because I’m forced to manually maintain header dependencies in the makefile.

  • 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-19T09:24:49+00:00Added an answer on May 19, 2026 at 9:24 am

    I have done similar setup in VS2008, which I think still applicable for you in VS2010.

    To start, I setup my project hierarchy as Build, ProductionCodeBase and TestCodeBase.
    Common interface/headers are extracted into folder accessible by all projects.

    Then in my “Build” project, I manually add object file(s) from ProductionCodeBase into “Release” configuration, and object file(s) from TestCodeBase into “Debug” configuration.

    Don’t forget to set project dependencies so that object file are valid when linking in “Build“.

    Do note that you can create project that only compile source code into object files without attempt to link them. Just go to “Tool Build Order” for that particular project and disable corresponding linker.

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

Sidebar

Related Questions

I have created a static library in Iphone SDK in which I used some
I have used a static global variable and a static volatile variable in file
I have a class which contains a static collection that can be used across
Is it possible to have a C static library API, which uses C++ internally
I have a static library that is used in production code and test code.
I have a library of static final Java classes which describes a body of
So I have a static class that is supposed to be used as a
I have used this in my HTML: <q> Hai How r u </q> Which
Consider I have built DAL.dll which is a class library containing an Entity Framework
I'm currently in the process of developing a fairly large static library which will

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.