多项目 Visual Studio 2005 解决方案中的链接问题

发布于 2024-09-14 02:07:11 字数 1586 浏览 6 评论 0原文

我正在开发一个包含多个项目的解决方案文件(VS 2005)。

我现在关心的项目有两个——一个叫 core,另一个叫 log。

核心项目是启动项目,日志项目在其项目依赖项中勾选了核心。

我在核心项目中有两个文件 - AB.h(声明)和 AB.cpp(定义)

核心项目中的许多其他 cpp 文件引用 AB.h,并且在 AB.cpp 中查找定义没有问题。

现在问题来了。我在日志项目中有一个名为 CD.cpp 的 cpp 文件,需要引用 AB.h。我已将 AB.h 的包含目录添加到核心项目和日志项目中(AB.cpp 也位于同一文件夹中)

此外,日志项目的链接器部分的“附加库目录”参数中有 $(OutDir)项目设置。还将“core.lib”添加到“属性”->“链接器”->“输入”中的“附加依赖项”字段。

核心项目编译为 dll,但同一文件夹中还有一个 core.lib 和其他垃圾。解决方案编译为Release版本。

在 CD.cpp 中,当我右键单击 #include "AB.h" 行时,它会将我带到 core 文件夹中的 .h 文件。到目前为止一切都很好。但是,当我尝试编译解决方案时,日志项目无法正确构建,显示这两个链接器错误。

log.obj:错误 LNK2001:无法解析的外部符号“class myNamespace::myClass myInstance”(?myInstance@@3VmyClass@myNamespace@@A)

log.obj:错误 LNK2001:无法解析的外部符号“bool infFlag”(?infFlag@@3_NA) )

该类是 AB.h 中包含的 h 文件的一部分(在 AB.cpp 中声明的实例并作为 extern 包含在 CD.cpp 中。infFlag 在 AB.cpp 中声明并在 CD.cpp 中声明为 extern。

我该怎么办让日志正确构建?谢谢


,当然,

解决方案文件

一个

包含 AB.h 和 AB.cpp

-AB.h

-包含来自外部库的 EF.h。 正常工作)。

文件

库的

来自该

对于同一核心项目中的文件 没有问题

[/Core]

[日志 -> 项目依赖项 -> Core]

-No h 文件

-CD.cpp

--需要 AB.h 才能工作。单击并单击“打开文件”以打开真正的.h文件)

--使用AB.h中的函数

[/Log]

希望这能更好地让你们理解我的解决方案中的项目结构。

编译 Log 项目时出现问题。对于 AB.h 中的任何函数引用,它总是会出现链接错误,提示“无法解析的外部符号”。我猜这是因为它找不到 AB.h 中声明的函数的定义(可能是因为它是一个不同的项目)。由于 log 依赖于 core,并且 core 将在此时编译,因此我将 $(OutputDir) 添加到 Library 目录(core 和 log 都构建到同一目录中),以便它可以找到 core.lib 并添加“core .lib”到“链接器”下“输入”选项卡下的“其他依赖项”(在项目属性中)。

所以就这样吧。有什么想法吗?


I'm working on a solution file (VS 2005) which contains multiple projects.

There are two projects of my concern right now - one called core and another called log.

The core project is the startup project and the log project has core ticked in its project dependencies.

I have two files in core project - AB.h(declarations) and AB.cpp(definitions)

Many other cpp files from the core project refer to AB.h and has no issues finding the definitions in AB.cpp.

Now comes the issue. I have a cpp file called CD.cpp in the log project which requires referring to AB.h. I have added the include directory of AB.h to both the core and log projects (AB.cpp also resides in same folder)

In addition the log project has $(OutDir) in its "Additional Library Directories" parameter in the Linker part of project settings. Also have added "core.lib" to the Additional Dependencies field in Properties->Linker->Input

The core project compiles into a dll but there is also a core.lib in the same folder amongst other junk. Solution compiled as the Release version.

In CD.cpp, when I right click the #include "AB.h" line, it takes me to .h file in the core folder. So far everything is fine. However when I try to compile the solution, the log project does not build properly, showing these two linker errors.

log.obj : error LNK2001: unresolved external symbol "class myNamespace::myClass myInstance" (?myInstance@@3VmyClass@myNamespace@@A)

log.obj : error LNK2001: unresolved external symbol "bool infFlag" (?infFlag@@3_NA)

The class is part of an h file included in AB.h (instance declared in AB.cpp and included as extern in CD.cpp. infFlag is declared in AB.cpp and declared in CD.cpp as extern.

What do I do to let log build properly? Thanks


OK. You guys need more details. Sure.

One Solution file. Multiple Projects.

[Core]

includes AB.h and AB.cpp

-AB.h

--includes EF.h from external lib (functions from this lib is working properly for files within the same core project).

--declares some functions

-AB.cpp

--defines those functions which was declared in AB.h

-some other cpp files which can use those functions from AB.h without issues

[/Core]

[Log -> Project Dependencies -> Core]

-No h files

-CD.cpp

--requires AB.h to work. Is included with a #include command and its linked properly (I can right click and click "open file" to open the real .h file)

--uses functions from AB.h

[/Log]

Hopefully this will better let you guys understand the project structure in my solution.

Issue comes when compiling Log project. It always comes up with a link error for any references to functions in AB.h saying "unresolved external symbol". I guess this comes because it cannot find the definitions for the functions declared in AB.h (probably because it is a different project). Since log is dependent on core, and core will have compiled as of then, I added in $(OutputDir) to Library directories (both core and log build into the same directory) so that it can find core.lib and also added "core.lib" to "Additional Dependencies" under Input tab under Linker (in project properties).

So there you go. Any ideas?


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

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

发布评论

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

评论(1

峩卟喜欢 2024-09-21 02:07:11

此外,日志项目在项目设置的链接器部分的“附加库目录”参数中有 $(OutDir)。

可能是错的。应该是“core.lib”所在的目录,$(OutDir) 是放置log 的位置。

该类是 AB.h 中包含的 h 文件的一部分(在 AB.cpp 中声明的实例,并作为 extern 包含在 CD.cpp 中。infFlag 在 AB.cpp 中声明,并在 CD.cpp 中声明为 extern。

那么定义在哪里?

In addition the log project has $(OutDir) in its "Additional Library Directories" parameter in the Linker part of project settings.

Probably wrong. It should be that dir where "core.lib" resides, the $(OutDir) is where the log will be put.

The class is part of an h file included in AB.h (instance declared in AB.cpp and included as extern in CD.cpp. infFlag is declared in AB.cpp and declared in CD.cpp as extern.

So where are definitions?

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