Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ 2008 Express - cpp filename conflict

I'm developing application for GNU/Linux using gcc 4 and cmake to manage compilation process. I found that is has no problems when there are two files with the same name but in other directory and namespace like this:

.  
|-- gfx  
|   |-- Object.cpp  
|   `-- Object.h  
`-- logic  
    |-- Object.cpp  
    `-- Object.h  

First Object class is in Gfx namespace and second in Logic namespace.

Then I've tried to compile this project using Visual C++ 2008 Express Edition. Linker threw several errors about non-existing implementation of Gfx::Object class. After few checks I found out that:

  • Visual C++ is tracking two of Object.cpp files
  • When change occurs in first or second file the recompilation of Object unit is queued
  • It always recompile only the second Object.cpp regardless of which file was actually modified

I also found out that Visual C++ don't allow to create two classes with same name.

Is there a solution for this? I don't really want to refactor quite big part of code.


1 Answers

Both Object.cpp files will be compiled to Object.obj. Into the same directory. In other words, the last one that is compiled will overwrite the Object.obj of the first one. Yes, the linker isn't going to be thrilled by that, you'll get multiply defined symbols since it links the same Object.obj file twice.

The fix is easy, right-click one of the Object.cpp files, Properties, C/C++, Output Files. Change the Object File Name from $(IntDir)\ to, say, $(IntDir)\$(InputName)2.obj

like image 148
Hans Passant Avatar answered Nov 22 '25 00:11

Hans Passant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!