13

i have a largish C++ project, with source-files organised in multiple folders (on the filesystem).

in two of these folders, i have files with the same name. e.g.

\MyProject\foo\Blurp.cpp
\MyProject\foo\File.cpp
\MyProject\bar\File.cpp
\MyProject\bar\Knoll.cpp

the project is cross platform, and i use autoconf on linux and OSX, but have to use MSVC on W32 (due to some 3rd party C++ libraries i use on W32 and the C++ binary interface incompatibilities across compilers)

on the MSVC side, the project is organized into multiple "Filters" (those virtual Folders) as well (with names roughly corresponding to the Directories the files live in), so i can distinguish them.

now the problem is, when i build the project, MSVC puts the object files in a single flat diretory, and i end up with:

\MyProject\Release\Blurp.obj
\MyProject\Release\File.obj
\MyProject\Release\Knoll.obj

as can be seen, there's only one File.obj, so one binary object is missing. obviously, the linker complains, since it cannot find classes/functions/... defined in that missing object file.

is there a way to tell MSVC to create object files with a unique name depending on the directories (or filters) those files live in?

i imagine something like:

\MyProject\Release\foo\Blurp.obj
\MyProject\Release\foo\File.obj
\MyProject\Release\bar\File.obj
\MyProject\Release\bar\Knoll.obj

or

\MyProject\Release\foo-Blurp.obj
...

or whatever. all other build-systems i know (CMake, autotools) are able to deal with multiple files of the same name.

this question is similar to 3729515, but i'm currently stuck to VS2008. (the solution suggested there for VS2008 - to set the Object-Directory for each file in question - is something which indeed works theoretically, but which i would like to avoid for practical reasons)

4

3 に答える 3

18

おそらく、プロジェクト全体の「オブジェクトファイル名」(構成プロパティ-> C / C ++->出力ファイル)を次のように設定できます

$(IntDir)%(RelativeDir)

これは、ソース ファイルの相対ソース フォルダーを使用します。に注意してください。ただし%、ソース ファイルがプロジェクト ディレクトリの外にある場合、これは見苦しくなります。..\

于 2014-04-08T11:54:08.457 に答える
11

競合するファイルの一方 (または両方) にファイル固有のプロジェクト設定を設定し、[オブジェクト ファイル名] プロパティを次のように設定できます。

$(InputDir)\$(IntDir)\

プロジェクト名の代わりにファイル名を右クリックして、そのファイルのみのプロパティを設定します。

たとえば、これを行うと、\MyProject\foo\File.cppそのソース ファイルのオブジェクト ファイルは に移動する\MyProject\foo\Release\File.objため、 のオブジェクト ファイルと競合しません\MyProject\bar\File.cpp

これの欠点は、ソース ツリーがコンパイラ出力で乱雑になる可能性があることです (ただし、あまり多くないことを願っています)。 IDEはまったくありません。いつかあなた (または他の誰か) が物事を変更する必要がある場合、何が起こっているのかがわかるまで誰かが半日それをいじるまで、なぜビルドが特定のファイルに対してそれほど奇妙に動作するのかについては非常に謎です。の上。

個人的には、プロジェクト全体の設定で、オブジェクト ファイルがソース ファイルに関連するディレクトリに移動することを好み$(InputDir)\$(IntDir)\ますが、実際には、プロジェクト レベルの設定としてはまったくうまく機能しません。その場合でも、VS は出力ディレクトリを 1 回だけ設定し、最終的にはリスト内の最初のソース ファイルに相対的になります。次に、リンカーは、オブジェクト ファイルを探す場所について混乱します。

于 2013-01-17T07:01:00.000 に答える
0

使用する

$(IntDir)%(Directory)

「オブジェクトファイルパス」として。

%(Directory)ボリュームとファイル名自体を除いたファイルの絶対パスが含まれています。このソリューションは、少なくとも VS 2019 で機能し、プロジェクトに直接適用できます。

于 2019-12-09T19:39:37.707 に答える