如何在同一个项目中引用另一个VC ++项目? [英] How do I reference one VC++ project from another in the same project?
问题描述
我是Visual Studio的新用户。需要您的帮助。
I am new to Visual Studio. Need your help with the following.
Visual Studio 2005,VC ++
1解决方案有2个项目。
调用解决方案作为'解决方案'
项目1被命名为p1,项目2被称为'p2'
我需要导出函数和类从'p1'所以我可以通过导入在'p2'使用它们?
如果我只是包括头文件,然后使用函数,直接调用它们呢?
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?
感谢,
viren
Thanks, viren
推荐答案
正确地(一段时间没有使用C ++),有两种不同类型的C ++库 - 一个静态库(.lib文件)和一个动态库(一个.dll文件)。
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).
在静态库的情况下,你必须配置p2,使其链接到p1.lib(在项目属性中);将p1添加到p2的依赖项,以便始终首先构建;然后根据需要包括p1的.h文件。
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.
.dll文件有点棘手 - .h文件必须有 __declspec(dllimport)
和 __ declspec(dllexport)
我想。还有一些魔法。不确定真的。
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.
请注意,这是一个MS特定的关键字,不适用于其他编译器。
Note that this is a MS specific keyword and will not work on other compilers.
这篇关于如何在同一个项目中引用另一个VC ++项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!