Advertisement

Visual studio 2017 - Reference to a Project inside the same Solution

Started by July 19, 2017 04:27 AM
6 comments, last by Kylotan 7 years, 4 months ago

Image below, as you can see my "Init Direct3D" Demo project has a reference to "Direct3D Framework", and yet I cannot #include "D3DApp.h" ... what am I doing wrong? x_x

HOAc0kP.png

What's the error you get when you try?

Adding a "reference" to a native project like that isn't necessarily going to set up the include paths correctly; probably the only thing it's doing for you is ensuring the referenced project builds before the referring project. Depending on how you set it up, it may also be automatically linking in the static library output of the referenced project.

Chances are, you need to go into the project settings for your main project and find the include search paths option, and modify it to include a relative path from your project to the directory containing the D3DApp.h source code.

Or, frankly, not bother with a separate project for this and just lump it all into your main project. 

Advertisement

I think you where right about the paths, after adding include,reference and source path the intellisense now highlight all my classes and give no errors, but still it won't compile, image below x_x (apologize, my VS is not in english unfortunately)

 

hAt1pyL.png

Finally solved x_x

I had to go into my framework project and change it into a Static Library configuration from the project setting, it was set as an application before x_x

The static library configuration issue will have fixed those Linker errors (LNK1120).

However the initial problem, of being unable to #include a file, is all down to setting the correct include directories (i.e. in "Directory di inclusione").

These 2 concepts are (unfortunately) quite separate in C++, and with any application using multiple projects you typically have to do both things - make sure the #includes are visible, and make sure the .lib files are linked in to your final project or library correctly.

6 minutes ago, Kylotan said:

The static library configuration issue will have fixed those Linker errors (LNK1120).

However the initial problem, of being unable to #include a file, is all down to setting the correct include directories (i.e. in "Directory di inclusione").

These 2 concepts are (unfortunately) quite separate in C++, and with any application using multiple projects you typically have to do both things - make sure the #includes are visible, and make sure the .lib files are linked in to your final project or library correctly.

Yes, I ended up touching the include directories as well even though I didn't mentioned it.

Imo it's kind of ridiculous that something as simple as that requires turning all that knobs and pulling all that levers, but maybe is just me doing it wrong or being spoiled :D

Advertisement

This is how C++ works unfortunately. The system that operates the #includes (the preprocessor) is a completely different system to the one that links the compiled code together (the linker).

This topic is closed to new replies.

Advertisement