Sign in to follow this  
LowRad

Multiple projects solution in C++

Recommended Posts

Hi all, So long i didnt used C++ for any type of project. I've start using C# 6 years ago and never look back. Today, i've decided to build a little game. And i'm stuck layouting my solution, i just can't remember how to 'link' projects together. So, to start, i've layout my solution like this.. a Win32 application project named MyGame and another win32 lib project named GameFramework. My question is how can i reference GameFramework from MyGame? I'm using Visual Studio 2008 if that matters. I got a few ideas on how to do it, i was going to do like i do to link any other lib, but since all projects are in the same solution i bet there's a better way. Thanks, Jonathan

Share this post


Link to post
Share on other sites
Quote:
Original post by LowRad
...i was going to do like i do to link any other lib, but since all projects are in the same solution i bet there's a better way.
Not that I know of. You can set up the LIB as a dependancy of the EXE, but that just means that the LIB builds before the EXE.

If you want the EXE to use the LIB, you'll have to add it to the linker settings, or via a #pragma in a .cpp file.

Share this post


Link to post
Share on other sites
Wow that was fast, thanks...

That's just to prove me i didnt code in c++ for too long ;)

So, i really need to add the file.lib and add paths for lib and include paths right? like i do for any others 3rd party lib?

Jonathan

Share this post


Link to post
Share on other sites
Quote:
Original post by LowRad
Wow that was fast, thanks...

That's just to prove me i didnt code in c++ for too long ;)

So, i really need to add the file.lib and add paths for lib and include paths right? like i do for any others 3rd party lib?

Jonathan
Yup, again - as far as I know.

You could set up a post-build step to copy the headers and lib into your EXE directory, so you don't need to add everything to Visual Studio's directories if that helps. Then you can just #include "Header.h", and link to "library.lib".

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by LowRad
...i was going to do like i do to link any other lib, but since all projects are in the same solution i bet there's a better way.
Not that I know of. You can set up the LIB as a dependancy of the EXE, but that just means that the LIB builds before the EXE.

If you want the EXE to use the LIB, you'll have to add it to the linker settings, or via a #pragma in a .cpp file.


Actually, IIRC, in Visual C++ 2005 or 2008, if you make one project a dependency of the other, then the first one will automagically be linked to (or whatever the term is) by the second. At least, I don't remember doing anything else.

Give it a shot, LowRad. I think it will work. I think all you do is right click on one project (in the solution explorer to the left by default), go to dependecies, and add the other project.

Share this post


Link to post
Share on other sites
Yeah, VS 2005 and 2008 will automatically link libs that are set as dependencies under Solution Dependencies. You can verify that it works by looking at the Advanced option in the project settings Linker group.

You will, however, have to add the lib project's folder to the exe project's include path if you want to #include headers from the lib project in the exe project.

Share this post


Link to post
Share on other sites

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