开发者

reference other projects in visual studio for win32 projects

I am working with win32 API and my language of choice is pure C and no C++.

Assume I have a project A that is present in Solution S in visual studio

I want to add another project B(which has some common utility functions) in to S

Now I want to reference Project B in Project A... So that I can use those ut开发者_如何学Cility functions from Project B source code level. I dont want it be used against dll of Project B

assume project B contains some math related functions and i want to call the functions from Project A or project B contains come data structures and i want to make use of them in Project A

How to achieve this.... thanks in advance


If you dont want project B to be a DLL, then it MUST be a static library. It project B is already an EXE, then you need to add a 3rd project: Project C - A static library project that contains the source files shared between A and B. Projects A and B can either reference it, or list it as a project dependency.


Ok. If you create a solution in Devstudio with projects, then the default layout on disk will be something like - having created a Project 3 as a static library project:

c:\Projects\SolutionDir
                       \Project1
                       \Project2
                       \Project3

Move the source (.cpp) AND header files (.h) for the common structs and functions to Project 3.

In projects A and B, find Project Settings > Compiler > Additional Includes and add an entry that says

$(SolutionDir)

Now, in projects1 and 2, you can reference the header files from Project3 thusly:

#include "Project3/commonheader.h"
// or
#include "Project1/sharedFunctionDecls.h"
#include "Project2/sharedStructDefs.h"

Right click on Project1 (and then Project 2) and choose "Project Dependencies..." and tick Project 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜