0

I have an overall solution with two projects (let's say proj1 and proj2) within it. In proj1 there's a file called foo.cpp and a corresponding foo.h. In proj2 I use #include "../proj1/foo.h" so that's taken care of, but I get linker errors, and I suspect this is because it doesn't have access to foo.obj.

Is there a way to set up the project preferences so that proj2 can link to proj1 source files without having to copy them over from project to project? I'm not linking to any external libraries if that makes it easier.

rcplusplus
  • 2,767
  • 5
  • 29
  • 43
  • This has already been answered at this post: http://stackoverflow.com/questions/601268/visual-c-include-files-from-other-projects-in-the-same-solution – Zimad May 20 '15 at 18:59
  • @Zimad But both `proj1` and `proj2` create `.exe` files not `.lib` files – rcplusplus May 20 '15 at 19:02
  • There is no need to make a copy of the source file. Just right click somewhere in the second project, go to `Add | Existing Item...` and browse to the source file in the tree of the other project. – Steve May 20 '15 at 19:13
  • @Steve I tried that but I still get the linker errors – rcplusplus May 20 '15 at 19:18
  • Did you add the `.cpp` file to the project, or just the header? Without the implementation, you'll get unresolved external errors from the linker. – Steve May 20 '15 at 19:19
  • Post the linker errors. It sounds like you aren't linking to the .obj file, but we can't tell without seeing the errors. What you did with the .h file is correct. – Moby Disk May 20 '15 at 19:23
  • @Steve I added just the `.cpp` and set the `Additional Include Directory` to the where the `.h` files are. – rcplusplus May 21 '15 at 14:33

0 Answers0