Is it possible to have identically named source files in the same visual studio C ++ project?

I am working on a static library project for a C ++ course that I am taking. The teacher insists that we define only one function for the source file, grouping the files / functions belonging to one class in subdirectories for each class. This leads to a structure such as:

MyClass
    \MyClass.cc (constructor)
    \functionForMyClass.cc
    \anotherFunctionForMyClass.cc 
OtherClass
    \OtherClass.cc (constructor)

Whether this is good practice or not, this is something I would not want to discuss, as I simply have to organize my project in this way.

I work in visual studio 2008 and somehow get weird link errors when using the same named function (and thus the file name) in two classes. This, apparently, is due to the fact that the visual studio places all the files .obj(one for each source file) in one intermediate directory, overwriting previously created object files when compiling files with identical names.

This can be solved by placing the object files in subdirectories based on the relative path of the input file. Visual studio allows you to customize the names of the object files it creates and use macros there, but there is no macro for the "relative path of the input file".

So, is there a way to make this work? If not, does one project use the best way to work for each class?

+3
9
+6

:

C/++ = > = >

$(IntDir)/% (RelativeDir)/

.obj , .

+5

, , VStudio .

-

  • . IDE , , , , , , - . , . , , : Visual Studio , cpp cpp.

  • . libs obj .lib, .

  • comp-sci , . , : , , .

+4

. , .

+1

? ,

MyClass   \ MyClass.cc()   \ function1_MyClass.cc   \ function2_MyClass.cc

, , . ?

+1

, , , . , . ( , , , , reset ).

, , /C ++/Outpuf Files/Object File Name: $(InputDir) ( ). , .obj .

, Clean Solution, - .

+1
  • , , , / . , , , , Visual Studio, .

  • funciton ; myclass-ctor.cc, myclass-function1.cc ..

  • .cc , # . #included ( , Properties- > Exclude From Build "Yes" ).

, , , . , ?

, ?

- , ( pegery jiggery), , , , .

; ++, OO, , , .

+1

... .h .cc ? , , .

, , . , , , .

0

Visual Studio 2010

    Properties -> C/C++ -> Output Files -> Output File Name

    V:\%(Directory)$(PlatformName)_$(ConfigurationName)_%(Filename).obj

for OBJ files, so that they are close to the sources, assuming that the project is on disk V(I don’t know if there is a macro for it).

By the way: $(InputDir)refers to the solution / project directory and causes the same problem in another directory.

0
source

Source: https://habr.com/ru/post/1727221/


All Articles