Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two files of the same name give linker error in Visual Studio

I'm using Visual Studio 2010 to compile my C++ project, and the linker is barfing on two of my files which have the same name- but they're in completely different directories. How can I make the linker recognize that they are different files?

like image 355
Puppy Avatar asked Feb 19 '12 16:02

Puppy


People also ask

How to solve linker error in Visual Studio?

In Visual Studio, make sure the source file that defines the symbol gets compiled as part of your project. Check the intermediate build output directory for a matching . obj file. If the source file isn't compiled, right-click on the file in Solution Explorer and choose Properties to check the properties of the file.

How do I link an object file in Visual Studio?

You can try linking the object file to your application by: Go to project properties then from "Property Page" select the node "C/C++" their you will get "Additional Include Directories" add the name of your object file.


1 Answers

I believe the problem comes from the fact that all your .obj files are written to the same folder, and so the outputs from compiling those two source files are colliding. I think there are at least two possible solutions:

  1. Use a different output directory (build directory) for each input folder
  2. Create custom object file names for each (or just one) of your source files

I'm not certain about the first option, but for the second, you should be able to right-click the source file in the solution explorer, select "Properties", and find some configuration setting to over-ride the output (.obj) file created for that source file.

like image 194
aldo Avatar answered Oct 06 '22 00:10

aldo