問題描述
我剛剛被來自 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) 引用在函數(shù) void __cdecl test::identity::identity(void)
(?identity@YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbol void __cdecl test::identity::make(void)
(?maketest@@YAXXZ) 在函數(shù) void __cdecl test 中引用::identity::identity(void)
(?identity@YAXXZ)
1 range.obj : error LNK2019: unresolved external symbol void __cdecl test::range::is(void)
(?istest@@YAXXZ) 在函數(shù) 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 symbolvoid __cdecl test::identity::view(void)
(?viewtest@@YAXXZ) referenced in functionvoid __cdecl test::identity::identity(void)
(?identity@YAXXZ)
1 identity.obj : error LNK2019: unresolved external symbolvoid __cdecl test::identity::make(void)
(?maketest@@YAXXZ) referenced in functionvoid __cdecl test::identity::identity(void)
(?identity@YAXXZ)
1 range.obj : error LNK2019: unresolved external symbolvoid __cdecl test::range::is(void)
(?istest@@YAXXZ) referenced in functionvoid __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 ?
推薦答案
只是想交叉發(fā)布我認為是答案的內容,如果您打開整個項目的屬性,并更改 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"的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!