有没有一种方法,以OBJ文件从Visual Studio比较? [英] Is there a way to compare obj files from Visual Studio?

查看:239
本文介绍了有没有一种方法,以OBJ文件从Visual Studio比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C ++项目,构建多种配置(不只是调试/发布),这是一个相当庞大的工程。让我们把它叫做KitchenSink.vcproj

I've got a C++ project that builds in several configurations (not just Debug/Release), and it's a rather massive project. Let's call it KitchenSink.vcproj

我怀疑,这个项目构建的多件相同,无论配置。例如。与建筑/不统一code支持将无关紧要为不使用字符串源文件。

I suspect that many pieces of this project build identically, regardless of the configuration. E.g. Building with/without Unicode support will not matter for a source file that doesn't use strings.

这将导致同一个源文件被编译在多种配置,但生成(有效)相同的.obj文件。它不产生相同的文件,因为时间戳等被嵌入在文件中,但所有的目标文件的功能件将是相同的。

This would lead to the same source file being compiled in multiple configurations, but generating (effectively) the same .obj file. It doesn't generate the same file, because timestamps and the like are embedded in the file, but all the functional pieces of the object file would be the same.

有没有一种方法来检查呢?我想提取的KitchenSink件自身,更简单,项目,在那里他们只需要一次建成。这将加快生成时间,并简化我们的codeBase的。但是,我需要一种方法来自动寻找code,它建立相同的部分,无论配置。有没有一种简单的方法来做到这一点?

Is there a way to check this? I would like to extract pieces of KitchenSink to their own, simpler, projects, where they only need to be built once. This would speed up build times, and simplify our codebase. But I need a way to automatically find the parts of the code that build the same, regardless of configuration. Is there an easy way to do that?

编辑:明确我的观点。试想以下文件:

Clarifying my point. Imagine the following file:

// Some header file
int calculate_something(int a, int b);

// The source file
int calculate_something(int a, int b) {
    return a * b;
}

现在,该源文件没有任何与统一code。因此,如果我们在一个统一code配置构建它,然后用一个多字节的配置再建造它,我们只是在浪费时间。我们可以把它变成自己的静态库,这是建不统一code的支持,然后新的lib可以通过我的其他项目中使用。没有什么危险在这。

Now, that source file has nothing to do with Unicode. So, if we build it in a Unicode configuration, and then build it again with a MultiByte configuration, we're just wasting time. We could put it into its own static library, that's built without Unicode support, and then that new lib could be used by my other projects. There's nothing risky in that.

我只需要找到一个可以安全地移动到一个单独的项目这些文件。

I just need to find these files that can be safely moved to a separate project.

编辑:进一步澄清:

KitchenSink.vcproj has the following files (among others)
    StringUtils.h
    StringUtils.cpp
    MathStuff.h
    MathStuff.cpp

现在,如果您在单向code建造的KitchenSink,又在多字节,您将构建StringUtils.obj两次,两次MathStuff.obj。显然,这是必要的StringUtils.obj,因为这将是统一code和多字节不同。但MathStuff.obj应该建立完全一样的。

Now, if you build KitchenSink in Unicode, and again in MultiByte, you will build StringUtils.obj twice, and MathStuff.obj twice. Obviously, this is necessary for StringUtils.obj, since it will be different in Unicode and MultiByte. But MathStuff.obj should build the exact same.

所以,我想重新整理/重组/重构为以下内容:

So, I would like to rearrange/restructure/refactor to the following:

KitchenSink.vcproj has the following files (among others)
    StringUtils.h
    StringUtils.cpp

NewProject.vcproj has the following files
    MathStuff.h
    MathStuff.cpp

现在,的KitchenSink可以建在它的多种配置,而NewProject可以只用一个单一的调试/发布选项来构建。

Now, KitchenSink can be built in its multiple configurations, while NewProject can be built with just a single Debug/Release option.

再次我不是说有关共享OBJ文件。我说的是从一个项目删除CPP / h的文件,并且把它们放在另一个。

Again, I'm NOT talking about SHARING obj files. I'm talking about removing cpp/h files from one project, and putting them in another.

另外请注意,单向code /多字节是具有多个配置的一个项目的一个例子。在我的项目实际情况其实是比较复杂的,所以每一个源文件编译的4倍,而不是将与发生2单向code /多字节。

Also note that Unicode/Multibyte is an example of a project with multiple configurations. The reality in my project is actually more complicated, so each source file is compiled 4 times, rather than the 2 that would occur with Unicode/Multibyte.

推荐答案

要查看是否有项目正在建设中不同的配置相同的文件,但毫无意义,最好是比较preprocessor的输出。比较对象文件简直是太容易失败,而不是必要的。

To see if a project is building the same file in different configurations, but pointlessly, it is best to compare the output of the preprocessor. Comparing object files is simply too prone to failure, and not necessary.

的基本思路是:运行在多个配置文件中的preprocessor,并比较输出文件。如果他们是相同的,那么就没有多大意义,以建立对不同配置的文件,这是一个很好的候选人进行重构到不同的项目,用较少的配置。

The basic idea is: Run the preprocessor on a file in multiple configurations, and compare the output files. If they're identical, then there's not much point to building that file in the different configurations, and it's a good candidate to be refactored to a different project, with fewer configurations.

在Visual Studio:


  1. 在项目上右键单击,并转到属性

  2. 在配置属性 - > C / C ++ - > preprocessor,编辑生成preprocessed文件

  3. 设置为不带行号(/ EP / P)

  4. 在ConfigurationA做构建

  5. 的preprocessed文件在同一目录中的源文件生成,而不是在配置子目录,所以所有的 *。我文件移动到 ConfigurationA 子目录保管。

  6. 重复上述步骤 4 5 为ConfigurationB(以及任何其他配置)

  7. 比较个人 *。在每个配置子目录我文件。如果源文件产生相同的 .I 文件中的所有配置,这是提取到一个不同的(单配置)库中一个很好的候选人。

  8. 设置生成preprocessed文件回原来的设置。

  1. Right-click on the Project, and go to Properties
  2. Under Configuration Properties -> C/C++ -> Preprocessor, edit "Generate Preprocessed File"
  3. Set it to Without Line Numbers (/EP /P)
  4. do a build in ConfigurationA
  5. the preprocessed files are generated in the same directory as the source file, and NOT in the Configuration Subdirectory, so move all the *.i files to the ConfigurationA subdirectory for safe keeping.
  6. Repeat steps 4 and 5 for ConfigurationB (and any other configurations)
  7. Compare the individual *.i files in each Configuration subdirectory. If a source file produces the same .i file in all configurations, it is a good candidate to be extracted to a different (single-configuration) library.
  8. Set Generate Preprocessed File back to its original setting.

然而,如果你使用pcompiled头$ P $,这将很可能搞砸了。的precompiled头可以包括根本不需要由给定的文件的事,但会导致preprocessor输出到unecessarily改变

However, if you're using precompiled headers, that will probably mess this up. The precompiled header may include things that are simply not needed by a given file, but cause the preprocessor output to change unecessarily.

例如。 SimpleFile.cpp SimpleFile.h 只使用基本的类型,所以他们并不需要包括任何东西。但是, SimpleFile.cpp 包括的stdafx.h ,因为VisualStudio的要求在项目中的每个文件,包括precompiled头。 的stdafx.h 包含几个文件,包括 HighlyConfigurable.h - 其中有几个 #IFDEF 语句和行为有很大不同,这取决于配置。因此,由于 SimpleFile.cpp 包括的stdafx.h ,其中包括 HighlyConfigurable.h 中,preprocessor输出 SimpleFile.i 将每个配置完全不同。然而,如果的stdafx.h 都没有使用, SimpleFile.i 将在所有配置均相同。

E.g. SimpleFile.cpp and SimpleFile.h only use basic types, so they don't need to include anything at all. But, SimpleFile.cpp includes stdafx.h, because VisualStudio requires every file in a project to include the precompiled header. stdafx.h includes several files, including HighlyConfigurable.h -- which has several #ifdef statements, and behaves very different, depending on the configuration. Thus, since SimpleFile.cpp includes stdafx.h which includes HighlyConfigurable.h, the preprocessor output SimpleFile.i will be quite different for each configuration. Whereas, if stdafx.h were not used, SimpleFile.i would be the same in all configurations.

的简单的解决方法这里是注释掉的stdafx.h 的全部内容。这听起来激烈,但你不会将文件保存这样 - 你只是要按照上述步骤生成preprocessor文件进行比较,然后再还原的stdafx.h 其昔日的辉煌。

The simple workaround here is to comment out the entirety of stdafx.h. That may sound drastic, but you're not going to save the file that way - you're just going to follow the steps above to generate preprocessor files for comparison, and then restore stdafx.h to its former glory.

这篇关于有没有一种方法,以OBJ文件从Visual Studio比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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