Visual Studio includes
I was hoping to get some simple advice on this. I am wanting to setup my directory layout for my project as:
I am also hoping to just be able to do #include "file.h" instead of having to do #include "include/file.h". Now, if I don't put the include directory path part of that it can't find its own files despite their being listed under the header files. Is there a way to set the project's include directory path in VS (specifically 2010)? The way I was using before was to include the project's own path in its include directories project settings but after upgrading to VS2010 it is now confusing the linker into thinking that 2 copies exist and as such is duplicating declarations.
Thanks in advance,
Just to add, this ONLY happens in VS2010. It seems like it is somehow finding the files twice and if any of you guys are familiar with Ogre3D this is also how they configure their include directories and this also happens in their projects as well. I just can't find a fix for this.....
This should still work.
Originally Posted by Aetas
It does, actually. But after doing so it starts listing each include file twice and when I try to link my project together, it is managing to bypass my include guard that should only allow that file to be included once otherwise. Here's the warning I'm getting:
2>AuroraD3D9RenderSystem.obj : warning LNK4006: "struct Aurora::Gfx::D3D9DisplayModeFormatEntry * Aurora::Gfx::D3D9DisplayModeFormats" (?D3D9DisplayModeFormats@Gfx@Aurora@@3PAUD3D9Displ ayModeFormatEntry@12@A) already defined in AuroraD3D9Window.obj; second definition ignored
2>AuroraD3D9Adapter.obj : warning LNK4006: "struct Aurora::Gfx::D3D9DisplayModeFormatEntry * Aurora::Gfx::D3D9DisplayModeFormats" (?D3D9DisplayModeFormats@Gfx@Aurora@@3PAUD3D9Displ ayModeFormatEntry@12@A) already defined in AuroraD3D9Window.obj; second definition ignored
These are both in 1 include file that is included in both AuroraD3D9Window.h and AuroraD3D9RenderSystem.h except it is wrapped in an include guard. Somehow, that is getting bypassed and I don't understand why. I mean both of those files are in the same library....how is it bypassing the include guard?
Where is 3D9DisplayModeFormats defined?
You realize that include guards protect the same source file from including the same header more than once, right?
That means every source file will get its own D3D9DisplayModeFormats variable. That is where you warnings originate from.
You should not define variables in headers. They should be defined in source files.
Hrmm....so declare the variable in the common file and stick its initialization in a source file for it?
Absolutely. And don't forget to put "extern" before your declaration.
Alright, looks good. Appreciate the help :)