Wednesday, February 17, 2010

Project with 2 CPP files with the same name in different folders.

This comes as a surprise. I have a C++ project in which the code has been split across several folders. I have two .CPP files of the same name (utility.cpp) in two different folders. The content in the files is not the same. Different symbols defined in each. Sounds like this should work without a hitch, right?

I'm not yet sure of this but it looks like there is no straightforward way to do this in VS2008. Both files are compiled to the same output folder. It looks like the compiler (cl.exe) compiles both .CPP files to the same .OBJ file. So, the last compiled .CPP wins. By the time the linker (linker.exe) reaches the scene, only the symbols defined in the last compiled .CPP are available and the linker fails giving you "LNK2028: unresolved token".

I looked at VS2008 options to see if there was a way to include the relative path of the source file as part of the compiler's output file path, but so far I have not been successful.

Here's the  related post on stackoverflow.com.

No comments:

About Me

My photo
C/C++ Programmer doing CAD on Windows. Some web development experience. Bangalorean.

Blog Archive

Labels