Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
754 views
in Technique[技术] by (71.8m points)

visual studio 2008 - VisualStudio project with multiple sourcefiles of the same name?

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.

MyProjectfooBlurp.cpp
MyProjectfooFile.cpp
MyProjectarFile.cpp
MyProjectarKnoll.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:

MyProjectReleaseBlurp.obj
MyProjectReleaseFile.obj
MyProjectReleaseKnoll.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:

MyProjectReleasefooBlurp.obj
MyProjectReleasefooFile.obj
MyProjectReleasearFile.obj
MyProjectReleasearKnoll.obj

or

MyProjectReleasefoo-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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe you can set the project wide 'object file name' (Configurtion Properties->C/C++->Output Files) to

$(IntDir)%(RelativeDir)

which uses the relative source folder of the source files. Note the %, but this gets ugly if your source files are located out of your project directory, containing ..


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...