Visual Studio 2010& 2008不能处理在不同文件夹中具有相同名称的源文件? [英] Visual Studio 2010 & 2008 can't handle source files with identical names in different folders?

查看:229
本文介绍了Visual Studio 2010& 2008不能处理在不同文件夹中具有相同名称的源文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直接问题:如果我有两个文件名相同(但在不同的目录),似乎只有Visual Studio 2005可以处理这个透明? VS 2008& 2010需要一堆调整?除了我的命名约定,我做错了什么?

Direct Question: If I have two files with the same name (but in different directories), it appears that only Visual Studio 2005 can handle this transparently?? VS 2008 & 2010 require a bunch of tweaking? Aside from my naming convention, am I doing something wrong?

背景

我正在开发C ++统计库...我有两个文件夹:

I'm developing C++ statistical libraries... I have two folders:

/ Univariate

Normal.cpp
Normal.h
Beta.cpp
Beta.h
Adaptive.cpp
Adaptive.h

/ Multivariate

Normal.cpp
Normal.h
Beta.cpp
Beta.h
Adaptive.cpp
Adaptive.h

我需要支持交叉编译 - 我使用g ++ / make将这些相同的文件编译成Linux中的库。他们的工作很好。

I need to support cross compilation -- I'm using g++/make to compile these same files into a library in Linux. They work just fine.

我一直在使用Visual Studio 2005没有问题,但我需要升级到Visual Studio 2008或2010(目前流行在nVidia的nsight工具)。但是,如果我向具有相同名称的项目添加文件(即使它们在不同的目录中),我会遇到问题。我愿意改变我的命名约定,但我很好奇,如果其他人遇到这个问题,并发现任何很好的文档解决方案

I had been using Visual Studio 2005 without issue, but I need to upgrade to Visual Studio 2008 or 2010 (currently drooling over nVidia's nsight tool). However, I'm having trouble if I add files to a project with the same name (even if they're in a different directory). I'm willing to change my naming convention, but I'm curious if others have encountered this problem and have found any well documented solutions??

我进一步讨厌的事实,如果我从2005年项目升级到2010年项目,似乎VS 2010 能够正确处理两个源文件在相同的名称在不同的目录;但是,如果我删除一个重复的文件,然后将其添加回项目我受到以下警告:

I'm further boggled by the fact that if I upgrade from 2005 projects to 2010 projects, it appears that VS 2010 is able to correctly handle two source files with the same name in different directories; however, if I remove one of the duplicate files and then add it back to the project I am greeted by the following warning:

分布\Release\Adaptive.obj :warning LNK4042:对象指定多次; extras ignored

Distributions\Release\Adaptive.obj : warning LNK4042: object specified more than once; extras ignored

现在我有中间目录指定为$(ProjectName)\ $(配置) - 我需要有我的目标文件在不同的位置从我的源树。所以我可以看到为什么它复制对象文件在彼此的顶部,但当项目从2005年转换到2008年或2010年,添加一堆条件编译:

Now I have the intermediate directory specified as $(ProjectName)\$(Configuration) -- I need to have my object files in a different location from my source tree. So I can see why it's copying the object files on top of each other, but when the projects are converted from 2005 to 2008 or 2010, a bunch of conditional compiles are added:

<ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)%(Filename)1.obj</ObjectFileName>
<XMLDocumentationFileName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(IntDir)%(Filename)1.xdc</XMLDocumentationFileName>

这些可以从C / C ++中的源文件属性页 - >输出文件 - >对​​象文件名& XML文档文件名。但是如果我直接添加文件(或删除和重新添加它们),VS不抱怨直到我尝试编译,但也从不添加条件指令 - 所以为了让东西正常工作,我必须为每个单独的配置自己添加条件指令。

These are accessible from the Source file Properties page in C/C++ -> Output Files -> "Object File Name" & "XML Documentation File Name". But if I simply add the file directly (or remove and re-add them), VS doesn't complain until I try to compile, but also never adds the conditional directives -- So in order for things to work correctly, I have to add the conditional directives myself for every single configuration. Am I making a mistake / poor assumption or have I uncovered a valid bug in VS 2008 / 2010?

推荐答案

所以@Hans Passant是一个错误/不好的假设或者我发现了一个有效的错误VS 2008 /指向正确的方向,谢谢!你不必列出文件,一个文件夹就足够了。然后,如果您查看VS 2010列表底部定义的宏,您将看到:

So @Hans Passant pointed in the right direction, Thanks!! You don't have to list the file, a folder is sufficient. Then if you look in the defined macros at the bottom of the VS 2010 list, you'll see:

%(RelativeDir)/单变量/

%(RelativeDir)/ Univariate/

发布的问题实际上是我正在处理的一个简化版本 - 在单个项目中的几个级别的文件夹,有几个名称冲突。因此,我真的想要一些只是修复它...

The problem, as posted, was actually a simplified version of what I'm working on -- a couple of levels of folders in a single project and there are a couple of name conflicts. Hence, I really wanted someway to just "fix" it...

如果你右键单击解决方案资源管理器中的项目,选择C / C ++ - >文件并在对象文件名框中键入以下内容:

If you right click on the project in the solution explorer, choose C/C++ -> "Output Files" and type the following into the "Object File Name" box:

$(IntDir)/%(RelativeDir)/

$(IntDir)/%(RelativeDir)/

请注意,我也从下拉列表中选择了(所有配置,所有平台)。这将编译镜像源树的目录层次结构中的每个文件。 VS2010将通过创建这些目录(如果它们不存在)开始构建。此外,对于那些在其目录名称中憎恨空格的人,此宏将删除所有空格,因此在使用时不需要使用双引号。

Note that I also selected (All Configurations, All Platforms) from the drop downs. This will compile every file in a directory hierarchy which mirrors the source tree. VS2010 will begin the build by creating these directories if they don't exist. Further, for those who hate white space in their directory names, this macro does remove all spaces, so there is no need to play around with double quotes when using it.

这是确切我想要的 - 与我的Makefile在Ubuntu一边工作,而仍保持源代码树干净的方式。

This is exactly what I wanted -- identical to the way my Makefiles work on the Ubuntu side, while still keeping the source tree clean.

这篇关于Visual Studio 2010&amp; 2008不能处理在不同文件夹中具有相同名称的源文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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