Home Dashboard Directory Help
Search

Visual C++ compilers only one file of two with the same name by Sergey Shandar citylizard


Status: 

Closed
 as Fixed Help for as Fixed


6
0
Sign in
to vote
Type: Bug
ID: 361228
Opened: 8/10/2008 6:27:45 PM
Access Restriction: Public
3
Workaround(s)
view
6
User(s) can reproduce this bug

Description

If two C++ files in the project have the same name, VC++ compiles only one of them.
Details
Sign in to post a comment.
Posted by mikeocool on 5/25/2010 at 3:31 PM
This issue does not appear to be fixed in Visual Studio 2010. Regardless of how the source code files are structured, all of the compiled .obj files appears to get dumped into the same directory, so if you have a file called \src\Example.cpp and a file called \src\another_namespace\Example.cpp they both seem to get compiled to Example.obj and one overwrites the other.
Posted by Microsoft on 8/14/2008 at 9:59 PM
Hi,

Thanks for your feedback. The issue you are experiencing is by design in Visual Studio 2008. To get around the issue you can rename the file to a different name.

However this should work in the next version of Visual Studio.

Thanks,

VC++ Team
Posted by Microsoft on 8/10/2008 at 9:33 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Posted by Microsoft on 8/10/2008 at 9:33 PM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team
Sign in to post a workaround.
Posted by Adam Badura on 7/11/2012 at 11:34 PM
You can also solve the issue on project level by changing in "C/C++" / "Output Files" both "Object File Name" and "Generated XML Documentation File" from default "$(IntDir)" to "$(IntDir)%(RelativeDir)". This will be then applied to each and every source file without the need to do anything more or manually change settings for individual files.

There is however a drawback. This approach seems to not work well if you have source files outside of the project folder. And this does happen with C++/CLI projects (at least on Visual Studio 2010) which implicitly use a ".NETFramework,Version=v4.0.AssemblyAttributes.cpp" file located in temp directory. "%(RelativeDir)" for such files is the full path and the above concatenation with "$(IntDir)" gives invalid path.
Posted by DS8 on 9/8/2009 at 4:27 PM
Change the name of the obj file for one of them, or preferably the two of them(e.g. to main_a.obj and main_b.obj)

From Solution Explorer, right-click on the file in question then choose properties, go to C/C++ > Output Files, change "Object File Name" to $(IntDir)\main_2.obj
Posted by Sergey Shandar citylizard on 8/10/2008 at 6:48 PM
Workarounds:

1. Rename files which have the same names.
     a\main.cpp => a\a.main.cpp
     b\main.cpp => b\b.main.cpp

2. Put these conflict files to separeted libraries.
     a\main.cpp =compile=> a.main.lib
     b\main.cpp =compile=> b.main.lib

3. Include these files to others as header files.

     a.main.cpp:
        #include <a/main.cpp>

     b.main.cpp:
        #include <b/main.cpp>