链接器无法识别某些#includes?
我有一个包含多个项目和多个命名空间的 VC++ 解决方案。每个项目都有自己的命名空间,有些项目有多个命名空间。
有时,当我引用另一个项目中的对象时,即使我 #included 头文件并通过其命名空间 (Namespace::object) 引用该对象,我最终也会遇到“无法解析的外部符号”错误。为了消除链接器错误,我还必须#include cpp 文件,然后我收到该符号被定义两次的警告。
这是非常hackish的,我不喜欢hackish。
我知道我需要仔细检查并查看所有包含的依赖项,因为显然有些事情搞砸了,但到目前为止我还没有发现任何主要问题。
同时,是否有人对任何明显需要检查的内容或此问题的任何常见原因有任何建议?
I have a VC++ solution with multiple projects and multiple namespaces. Each project has its own namespace, and some projects have multiple namespaces.
Sometimes, when I reference an object from another project I will end up with "unresolved external symbol" errors even though I #included the header file and referenced the object through it's namespace (Namespace::object). In order to get rid of the linker errors I have to also #include the cpp file, then I get warnings that the symbol was defined twice.
This is very hackish and I don't like hackish.
I know that I need to go through and look at all the include dependencies, since something's obviously screwed up, but I haven't been able to find any major problems as of yet.
In the mean time, does anyone have any suggestions for anything obvious to check or any common causes to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
“无法解析的外部符号”是链接器错误。并且链接并不关心#included 的内容(除非涉及#pragmas)。所有链接关心的是您明确声明要链接的内容。
您尝试使用的其他项目在编译时必须生成一个库或其他东西,对吗?您应该链接到项目设置中的那些内容。
"unresolved external symbols" are linker errors. And linking doesn't care about what gets #included (not unless there are #pragmas involved). All linking cares about is what you explicitly state you're linking with.
Those other projects you're trying to use must produce a library or something when you compile them, right? You should link to those in your project settings.
如果您使用的是 Visual C++,请转到项目属性的
Linker > 下输入
,添加你所依赖的项目编译好的.lib
文件。就像其他人所说的那样,您缺少的编译单元与您的文件 #include 无关(仅与编译相关,与链接无关)
If you are using Visual C++, Go to your project properties, under
Linker > Input
, you should add the compiled.lib
file of the project you are depending on.Like others have stated, the compilation unit you are missing has nothing to do with files you
#include
(which are only relevant for compilation, not linkage)链接目标文件不是使用
#include
预处理器命令完成的,而是通过 VC++ 本身或(非标准)#pragma
命令完成的。Linking object files is not done using
#include
preprocessor commands, but through VC++ itself or (non-standard)#pragma
commands..