How do I reference one VC++ project from another in the same project?

江枫思渺然 提交于 2019-12-31 03:50:13

问题


I am new to Visual Studio. Need your help with the following.

Visual Studio 2005, VC++
1 solution has 2 projects.
Lets call the solution as 'solution'
Project 1 is named 'p1' and project 2 is called 'p2'
Do I need to export functions and classes from 'p1' so that I can use them by importing in 'p2'?
What if I simply include the header files and then use the functions by calling them straight away?

Thanks, viren


回答1:


If I remember correctly (haven't used C++ for a while), there were two different kinds of C++ libraries - a static library (a .lib file) and a dynamic library (a .dll file).

In the case of a static library you had to configure p2 so that it links to p1.lib (in project properties); add p1 to dependancies of p2, so that it is always built first; and then include the .h files from p1 as necessary.

The .dll file was a bit more tricky - the .h files had to have __declspec(dllimport) and __declspec(dllexport) I think. And there was some more magic. Not sure really. But these are the keywords that might get you up and running.

Note that this is a MS specific keyword and will not work on other compilers.




回答2:


All you need to do to use these functions is to change the projects dependencies.

Right click on p2(or p1), select "Project Dependencies" Select p1(or p2) and include what you want to use. It's that simple.



来源:https://stackoverflow.com/questions/1201959/how-do-i-reference-one-vc-project-from-another-in-the-same-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!