Visual Studio 2010的奇怪的“警告LNK4042” [英] Visual Studio 2010's strange "warning LNK4042"

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

问题描述

我刚刚被Visual Studio 2010(C ++)的一些非琐碎的警告打败了(很少)。



编译提供了以下内容输出:


1 Debug \is.obj:warning LNK4042:object specified more than once; extras ignored

1 Debug \make.obj:warning LNK4042:对象指定了多次; extras ignored

1 Debug \view.obj:warning LNK4042:对象指定了多次; extras ignored

1 identity.obj:error LNK2019:未解析的外部符号 void __cdecl
test :: identity :: view(void)
(@ identity @ 0test @@ YAXXZ)在函数 void __cdecl test :: identity :: identity(void)
1 identity.obj:error LNK2019:未解析的外部符号 void __cdecl test :: identity :: make(void)(?make @ identity @ test @@ YAXXZ )
引用的函数 void __cdecl test :: identity :: identity(void)(?identity @ 0test @@ YAXXZ)

1 range.obj:错误LNK2019:未解析的外部符号 void __cdecl test :: range :: is(void)(?is @ range @ test @@ YAXXZ)在函数 void __cdecl test :: range :: range(void)(?range @ 0test @@ YAXXZ)


链接器错误总是很难调试...但有未解决的引用,所以我检查...但源是良好的形式...最后它打我:



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

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

,解决方案中的层次结构也是如此(我总是设置它,以便它模仿真正的文件夹结构) / p>

诊断输出:

  Debug \is.obj 
Debug \make.obj
Debug \view.obj

一个警告,表示 .obj 已经两次传递给链接器,并且将被忽略。



没有搜索:Visual已经整理了我的文件夹层次结构,因此无法整洁地编译源。



目前,我只是想重命名文件,应该包括这个问题...



...但是有一种方法让Visual Studio不展平文件层次结构?


<只要想交叉发布我相信是答案,如果你打开整个项目的属性,并改变C / C ++下的值 - >解决方案

输出文件 - >对​​象文件名如下:



$(IntDir)/%(RelativeDir)/


$ b在VS 2010,我相信这将消除所有的目标文件(因为我相信窗口不会让你在任何疯狂的情况下有两个文件在同一目录中具有相同的名称)。另请查看详情这里


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

The compilation gave the following output:

1 Debug\is.obj : warning LNK4042: object specified more than once; extras ignored
1 Debug\make.obj : warning LNK4042: object specified more than once; extras ignored
1 Debug\view.obj : warning LNK4042: object specified more than once; extras ignored
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::view(void) (?view@identity@test@@YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity@0test@@YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::make(void) (?make@identity@test@@YAXXZ) referenced in function void __cdecl test::identity::identity(void) (?identity@0test@@YAXXZ)
1 range.obj : error LNK2019: unresolved external symbol void __cdecl test::range::is(void) (?is@range@test@@YAXXZ) referenced in function void __cdecl test::range::range(void) (?range@0test@@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).

And the diagnostic outputs:

Debug\is.obj
Debug\make.obj
Debug\view.obj

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

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...

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

解决方案

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)/

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”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆