如何在同一个VC中链接到项目生成的.lib++ 2010年解决方案

发布于 2024-10-12 05:43:32 字数 395 浏览 3 评论 0原文

我有一个包含多个项目的 VC++ 2010 解决方案,其中一个是我希望将一些通用代码放在一个地方而生成的 .lib。

我现在正在尝试让另一个项目(一个普通的控制台应用程序)链接到该库。然而,VS 抱怨它找不到 .lib,即使我将其添加为附加依赖项。

我有点希望 VS 能让我轻松一些,因为 .lib 位于同一个解决方案中,尽管在不同的项目中,但遗憾的是,没有运气。

编辑我一定是瞎了,但我似乎找不到蒂姆提到的“附加路径”选项。我将 lib 项目添加到控制台项目的项目依赖项中,但它仍然不起作用。

EDIT2 在我实际将 .cpp 和 .h 文件添加到 .lib 项目后,Edwin 的建议起到了作用。当我错过如此明显的事情时,我真的很讨厌。

I have a VC++ 2010 solution with multiple project, one of which is a .lib produced by my desire to put some common code in a single place.

I'm now trying to get another of the projects, which is a normal console application, to link to this library. However, VS is complaining that it can't find the .lib even though I added it as an additional dependency.

I was kind of hoping that VS would make it easy on me since the .lib is in the same solution, albeit in a different project, but sadly, no luck.

EDIT I must be blind but I can't seem to find the 'additional paths' option Tim mentioned. I added the lib project to the project dependencies of the console project, but it still isn't working.

EDIT2 Edwin's suggestion did the trick after I actually added the .cpp and .h files to the .lib project. I really hate it when I miss something so obvious.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纵性 2024-10-19 05:43:32

properties_>Common Properties->Framework >中可执行文件的依赖项 您可以添加可执行文件所依赖的项目。之后,您只需调整C++->General附加包含路径即可让它找到您的包含文件。

编辑:我有一个名为 AppTest 的 exe 项目和一个 lib 项目 Dummy。

我将项目 Dummy 添加到 Framework & AppTest 的依赖项。

然后我调整了所有配置,将 AppTest 的包含路径指向 Dummy 的目录。

然后我将 dummy.h 包含在 apptest.cpp 中,并调用 dummy.lib 中的函数。

构建解决方案。就这样。

In the properties_>Common Properties->Framework & dependecies of your executable you can add projects on which your executable is dependant of. After that you only need to adjust additional include paths of C++->General to let it find your include-file.

EDIT: I have an exe-project named AppTest and a lib-project Dummy.

I added the project Dummy to Framework & dependecies of AppTest.

Then i adjusted for all configurations the include paths of AppTest to point to directory of Dummy.

Then i included dummy.h in apptest.cpp and a call to a function from dummy.lib.

Build the solution. That's all.

究竟谁懂我的在乎 2024-10-19 05:43:32

在 Visual C++ 中链接库有三种(也许更多:-)方法。您可以通过执行添加现有项并指向 lib 文件来在项目中显式包含 .lib 文件。这样你就不需要指定路径。您可以在选项/链接器/输入中添加文件,并在其他库目录中指定路径。最后,您可以使用 #pragma comment( lib, "my.lib") 并像以前一样指定路径。我不确定,但我认为上面的编译指示也允许放置完整路径。

There are three (maybe more :-) ways of linking a library in Visual C++. You can explicitly include .lib file in the project by doing Add Existing Item and pointing to the lib file. That way you don't need to specify the path. You can add a file in Options/Linker/Input and specify path in Additional Library Directories. And finally, you can use #pragma comment( lib, "my.lib") and specify the path as before. I'm not sure, but I think the above pragma also allows to put the full path as well.

放肆 2024-10-19 05:43:32

更改项目中依赖于该库的“其他路径”属性。

Change the "Additional paths" property(ies) in the project that is dependent on the lib.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文