jlengrand
jlengrand

Reputation: 12807

Using sub projects in Visual Studio

I am quite used to Linux development and Makefiles, and started using (Windows and) Visual Studio not so long ago.

What I want to do is (I think) quite simple, but I can't seem to find how to do it using Visual Studio.

I have to write an application, which I can divide into several independent sub-parts. I want to work incrementally, and create several projects that together with a main file will end up with my full project.

What I basically want is to be able to write a small project, have a main for it so that I can fully test it, and use it as a dependency for the next project. In this case, the smaller main would be deactivated (or I can comment it), and I would just change the startup project. If I find a bug in a subset while writing my bigger software, I could just change the startup project and solve it at a smaller scale.

Well, that's what I do all day long in Python and Java.

I tried to create new projects into my project, but I always end up having linking problems, where my main projects knows about the files in the sub projects, but not the smaller ones, etc. . .

So, is there a guide somewhere I can find to work this way ?

Thank you

Upvotes: 1

Views: 3152

Answers (3)

kuperspb
kuperspb

Reputation: 339

Looks like you trying to do manual unit testing. Use something like Google.Test. You need to make test project for every lib.

We have directory with static libs projects. Another directory with tests projects. Every test solution contains one exe project and few existing lib projects. Every project have configured dependencies. You dont need to set additional dependencies of the linker manually (paths are evil, out dir for the lib file will be taken from project settings), open project properties with right mouse button, Common properties, Add new reference and select lib project. You only need to set additional include dirs.

When you find new bug - just open test project for the library with bug, add code which cause the bug, fix it, and be happy (and sometimes run all test). And even better - use TDD.

Upvotes: 0

jlengrand
jlengrand

Reputation: 12807

Thanks to Vaibhav, I was able to find a solution:

I had to :

  • change subproject type to lib instead of exe
  • Add the subprojects as project dependencies in the main project (this just sets the build order)
  • Comment out the main of my subprojects, to keep only one active.
  • Add each subproject include directory in the include repos of the main project, so that the compiler can find the header files
  • Add the general directory as a dependency for the linker (in this case, it is not the debug/release folder of the subprojects, but the output directory of the complete project).
  • Add the names of the lib files of the subprojects in additional dependencies of the linker of the main project.

To make it simple, the project dependencies capability of VS2010 just changes the order in which the projects are built. . . I miss Eclipse.

If I find a bug and want to test on of the subprojects, I have to :

  • change the startup project to be the subproject I want to change.
  • uncomment the corresponding main
  • change the project type to be exe instead of lib to be able to compile it.

Debug, and do everything back again to continue working on my main project. Quite boring, don't you think ?

Upvotes: 1

Vaibhav Desai
Vaibhav Desai

Reputation: 2728

For individual projects:

Every individual project property sheet has a C++ options page. Here you can specify the 'Addional Include Directories' in a comma separated form.

Similarly, there should be a property sheet for Linker where you can specify the 'Addional Include Dependencies' and the names of the libraries it depends on.

For linker dependencies of the main executable:

Go to that main project, go to its properties, go to common properties and select 'Framework and References'. This should give you a list of all the projecs that are in your solution. Keep adding them and Visual Studio should add the right linker flags automatically for you.

Sorry, have no access to the computer now else would have provided exact steps. Visual Studio can get tricky sometimes but once you use it, you'll be amazed by what it can do for you. Personally, I love it.

Hope this helps.

Upvotes: 2

Related Questions