views:

46

answers:

2

Lets say I have: a static library project called "LIB" a application project called "LIBAPP" a application project called "APP" a application project called "APPTEST"

When i add "LIB" to LIBAPP Project Dependencies, Visual Studio automatically links "LIBAPP" against LIB. But when i add APP to APPTEST Project Dependencies, it doesnt.

Since i am doing unit tests of APP's classes in APPTEST, i have to link against APP, therefore i am currently manually linking against all *.obj files of APP (hundreds...)

Since i have to change the link targets of APPTEST everytime i add or remove a *.cpp file from APP, this isnt a nice solution.

So is there a way to force Visual Studio to do this for me automatically, like it does when adding a static library Project Dependency ?

A: 

You can't "link against APP", as you've discovered.

One solution is to put all of APP's code into its own library, leaving APP as single source file that runs a function in that library. The you can make APPTEST another single source file that links against the new APP library.

RichieHindle
A: 

Making an application depend on another is useful for causing both apps to both be build (if necessary) when you hit Compile. If you have enough code in APP that you feel that you need to write unit tests for them, I think it would be best to break this code out into another library, and call it something like "LIBAPPUTIL" or some-such which depends on LIB, and APP will have to depend on both LIB and LIBAPPUTIL.

You have noble intentions. By putting the parts of LIBAPP into a separate library, you get a bunch of benefits:

  • You can build variations of LIBAPP that have different void main()s
  • You can build several LIBAPPUTILs, each of which test usage of different sets of dependent code.
  • You can have alternate implementations of LIBAPPUTIL that do not depend on LIB. If you're smart with how you use interface types (either C++ virtuals or C structures full of function poointers) you can completely abstract away APP's dependency on LIB.
Armentage