Visual Studio 2010 的奇怪“警告 LNK4042"

Visual Studio 2010#39;s strange quot;warning LNK4042quot;(Visual Studio 2010 的奇怪“警告 LNK4042)

本文介绍了Visual Studio 2010 的奇怪“警告 LNK4042"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚被来自 Visual Studio 2010 (C++) 的一些重要警告击中了(相当严重).

I've just been beaten (rather hardly) on the head by some non-trivial warning from Visual Studio 2010 (C++).

编译给出了以下输出:

1 Debugis.obj : 警告 LNK4042: 对象指定不止一次;额外被忽略
1 Debugmake.obj : 警告 LNK4042: 对象指定不止一次;额外被忽略
1 Debugview.obj : 警告 LNK4042: 多次指定对象;额外被忽略
1 identity.obj : error LNK2019: 未解析的外部符号 void __cdecltest::identity::view(void) (?viewtest@@YAXXZ) 引用在函数 void __cdecl test::identity::identity(void) (?identity@YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::make(void) (?maketest@@YAXXZ) 在函数 void __cdecl test 中引用::identity::identity(void) (?identity@YAXXZ)
1 range.obj : error LNK2019: unresolved external symbol void __cdecl test::range::is(void) (?istest@@YAXXZ) 在函数 void __cdecl test 中引用::range::range(void) (?range@YAXXZ)

1 Debugis.obj : warning LNK4042: object specified more than once; extras ignored
1 Debugmake.obj : warning LNK4042: object specified more than once; extras ignored
1 Debugview.obj : warning LNK4042: object specified more than once; extras ignored
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::view(void) (?viewtest@@YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity@YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::make(void) (?maketest@@YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity@YAXXZ)
1 range.obj : error LNK2019: unresolved external symbol void __cdecl test::range::is(void) (?istest@@YAXXZ) referenced in function void __cdecl test::range::range(void) (?range@YAXXZ)

链接器错误总是很难调试......但是有未解析的引用,所以我检查了......但源格式正确......最后它击中了我:

Linker errors are always a pain to debug... but there were unresolved references, and so I checked... but the source is well-formed... and finally it hit me:

我的文件夹层次结构如下:

My folder hierarchy looks like so:

src/
  identity/
    is.cpp
    make.cpp
    view.cpp
  range/
    is.cpp
    make.cpp
    view.cpp

解决方案中的层次结构也是如此(我总是对其进行设置,使其模仿真实"的文件夹结构).

and so does the hierarchy in the Solution (I always set it up so that it mimicks the "real" folder structure).

和诊断输出:

Debugis.obj
Debugmake.obj
Debugview.obj

伴随着一个警告,指出 .obj 已被传递给链接器两次,而那个将被忽略.

Along with a warning which says that the .obj has been passed twice to the linker and that one will be ignored.

不再搜索:Visual 已经整齐地扁平化我的文件夹层次结构,因此无法整齐地编译源代码.

Search no more: Visual has neatly flatten my folder hierarchy, and therefore is unable to neatly compile the source.

目前,我只是想重命名文件,这应该可以解决问题......

At the moment, I am simply thinking of renaming the files, that should cover the issue...

...但是有没有办法让 Visual Studio 不扁平化文件层次结构?

... but is there a way to have Visual Studio NOT flatten the file hierarchy ?

推荐答案

只是想交叉发布我认为是答案的内容,如果您打开整个项目的属性,并更改 C 下的值/C++ ->输出文件 ->目标文件名"如下:

Just wanted to cross post what I believe to be the answer, if you open the properties for the entire project, and the change the value under C/C++ -> Output Files -> "Object File Name" to be the following:

$(IntDir)/%(RelativeDir)/

$(IntDir)/%(RelativeDir)/

在 VS 2010 下,我相信这将消除所有目标文件的歧义(因为我相信 Windows 不会让您在任何疯狂的情况下在同一目录中有两个同名的文件).另请查看详细信息 这里.

Under VS 2010, I believe this will disambiguate all of the object files (as I believe windows won't let you under any crazy circumstances have two files with the same names in the same directory). Please also check out the details here.

这篇关于Visual Studio 2010 的奇怪“警告 LNK4042"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Visual Studio 2010 的奇怪“警告 LNK4042"

基础教程推荐