Sign in to follow this  

How to handle multiple projects with Visual Studio

This topic is 4302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am using Visual Studio .NET (2003) for a new project. To subdivide the game code into several parts I used one workspace and added projects for each separate module (like Graphics, Networking ..). The basic structure would be something like this: [Project Home] ........| ........[gfx] ...........|----VisualObject.h ...........|----VisualObject.cpp ........[test] ...........|----test.cpp where folders /gfx and /test each contain a project of the workspace. Now when I want to use a Class which has been declared and defined in the "gfx" Project in another project, I run into problems: Project "gfx" contains a class CVisualObject with a header file CVisualObject.h and an implementation file CVisualObject.cpp. To make use of this class in Project "test" too, I therefore inlclude the header file in the test project via:
//FILE: test/test.cpp

#include "../gfx/CVisualObject.h"

...
CVisualObject* vo = new CVisualObject();
...
delete vo;

and I make sure that project "test" has the "gfx" project in the list of project dependencies, and that the build order is such that gfx gets compiled before the "test" project is compiled. It compiles, but the relevant Linker information of the CVisualObject class is never found. The Linker says that the default constructor (CVisualObject()) symbol is unresolved. I declared this constructor in /gfx/CVisualObject.h and implemented it in /gfx/CVisualObject.cpp. The same problem occurs for any other function I define in the .cpp file. When just using this class in the "gfx" project it works fine, but trying to reference it from project "test" within the same workspace it seemes that the definition of the .cpp file is not available when the "test" project is built. If however I put the class implementation directly in the VisualObject.h file below the declaration, it will work. It will also work if I #include the VisualObject.cpp file instead of the .h file.. but well that's certainly not what I want. I want to keep the class declaration in the .h file and most - if not all - of the implementations in the .cpp. So can anybody tell me how I can use classes with the .h / .cpp separation scheme with other projects in the same Visual Studio workspace by just including the appropriate headers or what could be wrong with my setup? Any pointers would be much appreciated! Thank you. mcp [Edited by - mcp on March 2, 2006 3:49:47 PM]

Share this post


Link to post
Share on other sites
Are you compiling [gfx] as a static library (as opposed to exe application)?
Just a shot, apart from that, I can't find anything wrong with what you described.

Share this post


Link to post
Share on other sites
If you're using two projects, and would like to include one in the other, you need to add a reference to the project.

IE, Project test must have a reference to project gfx added.

Share this post


Link to post
Share on other sites
Quote:
Original post by Siberwulf
If you're using two projects, and would like to include one in the other, you need to add a reference to the project.

IE, Project test must have a reference to project gfx added.


To be honest, I didn't do any of these, and my multi-project solutions (with internal project dependencies) worked fine.

Share this post


Link to post
Share on other sites
Thanks for your replies.

@deffner:
I am compiling it as an exe. Would you see any problem with that?


@Silberwulf:
I added gfx as a reference to test but that didn't solve the problem.


The problem must be something very basic I suppose. I cannot imagine why it shouldn't work. So if you or anybody got any other hints that would be great.

Maybe I should look at a working minimal Multi-Project VS-Workspace and see if anything is different. If you know where I can find such an example please let me know, I will also try searching for it later.

Here is the Build output:


------ Build started: Project: gfx, Configuration: Debug Win32 ------

Compiling...
CVisualObject.cpp
Linking...

gfx - 0 error(s), 0 warning(s)


------ Build started: Project: test, Configuration: Debug Win32 ------

Compiling...
test.cpp
Linking...
test.obj : error LNK2019: unresolved external symbol "public: __thiscall CVisualObject::CVisualObject(void)" (??0CVisualObject@@QAE@XZ) referenced in function _WinMain@16
Debug/test.exe : fatal error LNK1120: 1 unresolved externals

test - 2 error(s), 0 warning(s)


---------------------- Done ----------------------

Build: 1 succeeded, 1 failed, 0 skipped



mcp

Share this post


Link to post
Share on other sites
Quote:
Original post by Emmanuel Deloget
1) menu "Project -> Project Dependencies"
2) select "test" in the combo box
3) check the "gfx" checkbox

It should link test with gfx - and you'll get rid of your "undefined external" error.

HTH,


Actually, that's what I did, but the problem persists. Do I need to build to a lib first and then link to it? That's what I saw as a recommendation in the other thread. Then again, I thought a multi-project build should be something which is supported by VS. Any ideas?

mcp

Share this post


Link to post
Share on other sites
Quote:
Original post by mcp
@deffer:
I am compiling it as an exe. Would you see any problem with that?


Yup, I would.

I just made a simple test solution.
First project just defined a single function test1().
test1.h and test1.cpp - as usual.
It did not defined main().
Second project included test1.h and called test1().
Also, it defined main().


Now, if I set both projects as .exe - it ends up with the problems you mentioned.
If first project is configured as static library (Configuration properties -> General -> Configuration type -> static library) - everything is fine.

Cheers.
~def

Share this post


Link to post
Share on other sites

This topic is 4302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this