3

私はC++ソリューションのコレクションを持っています。それらはすべて、共通コードのディレクトリを含んでいます。だけでなく#include、共通のソースファイルも個別に作成します。ディレクトリ構造の例を次に示します。

code/
    Common/
    ProjectA/
    ProjectB/

したがってProjectAProjectB両方にからのファイルが含まれますCommon。両方のプロジェクトの中間ディレクトリをに設定しましたcode/_build/Debug/Obj

ProjectA最初にビルドした場合、ソースProjectBから中間ファイルを再構築する必要はないと予想していました。Commonこれは起こっていません。ProjectBはそれらのオブジェクトファイルProjectAを再構築しています。再構築すると、それらも再構築されます。

これは、オブジェクトファイルが現在コンパイル中のプロジェクトによってビルドされていない場合に、条件付き再構築がトリガーされるかのようです。これは本当ですか?

一般的なコードからライブラリを作成することもできますが、これはオプションではありません。

4

1 に答える 1

2

It's as if a conditional rebuild will be triggered if the object file was not built by the project which is currently compiling. Is this true?

Yes. Each project maintains its own separate list of build files. Each project builds those files separately from every other object, because each project also maintains its own separate build options. Every project is separate from all others, even within the same solution.

The problem you describe has been encountered before. A long time ago in fact. The solution to it was, and remains, quite simple: create a third project which creates a static library of common code, which is linked by the other two projects. Indeed, static libraries exist for precisely this reason.

If circumstances forbid you from using the solution that was designed to solve this exact problem, then you have two choices:

  1. change those circumstances so that you can use the solution.
  2. accept the needlessly longer build times incurred by your situation.
于 2012-07-25T04:38:16.560 に答える