Sharing files between projects in Visual C++ 10 - c++

I've got a relatively simple setup in Visual Studio 2010- a main application and a DLL it depends on. I have a header that defines it's interface- how can I set up the header to be included in both projects? They are both in the same solution.

See my answer to this question, but its just that you are using a dynamic library.
In summary, the main application project should reference the DLL project for the purposes of linking, and the main project should include folder references so the compiler can access header files.

In the VC different projects are placed in a different subdirectories of the solution dir.
If you want include files from the other project, you need to explicitly add it's dir to the include search path:
right click on the ".exe" project in the solution explorer. Choose properties.
In the property window go to the "C/C++" section.
There is the "Additional Include Directories" property. Add your "dll" project directory there.

Related

create dll out of yaml-cpp source code

Newbie to windows. I need to use yaml-cpp library in a project, but I can't seem to compile it in windows. I tried everything (everhthing!) I could find but no place have the full answer, just tips for the process. but those tips don't help so much.
I did create shared lib in Ubuntu but can't create dll in windows.
can someone give the full explanation to get dll from source code?
(I also be grateful for explanation of how use the dll with it's includes).
Working with visual studio 2015.
So finally I got it.
for linux users - use cmake. for windows users - you can but I really don't recommend it unless you need cross compiling. Use visual studio: (explained for VS 2017)
First create new project with existing code.
The folder you pick should be "src" (in case of cpp-yaml).
When creating the project you need to choose type of project (exe, dynamic or static library), so choose dynamic library to create .dll or static to create .lib.
After creating your project go to your project properties, go to c/c++ tab --> General --> "additional include directories", and add your path to the headers folder ("include"). Do not add "cpp-yaml" inside the include folder, only "include".
Now build. In the console you can see where the library was created.
To use it, in case you made static library 4 things need to be done:
add to your project "#include cpp-yaml/yaml.h"
in properties:
in tab "c/c++" --> General --> "additional include directories", add the include folder path. (as before)
in tab "Linker" -->Input, add to the "Additional dependencies" your lib name (followed by semi-colon)
in tab "Linker" --> General, add to "additional library directories" the path to your lib.

How to auto add dependent projects to include path in Visual Studio

So I've always had to use the project's "Additional Include Directories" property to set relative paths to other (library) projects that I'm dependent on for a given solution.
So the solution structure is essentially:
My App.sln
-> My App.vcxproj
-> My Lib.vcxproj
What I want, is for My App project to automatically have the path to My Lib project files added as an entry in its "additional include directories" simply because My App is dependent upon My Lib.
I set the library / linkage dependency by adding it under "References" for My App, which beautifully means that My App will automatically link against My Lib's output .lib. PERFECT!
But... I don't see how to get the .h files from My Lib to be included into My App without manually specifying its path (or relative path) to My App project's "additional include directories" property.
I have lived with this for years, but I had to solve the linkage issue for a dependent dependent and found a very slick way to do that without having to touch project settings.
Which makes me think - surely there is a way to do the same for "project A is dependent on project B and hence should automatically search project B for #include references"
Am I out on wishful thinking limb? Or am I missing some great facility in VS?

Any way to include a batch of Library and Directory paths to "Include Additional Directories" Visual C++

Currently, when working on a new solution in Microsoft Visual Studio 2017 (C++), my team has to include a bunch of libraries and directories individually. Which is tedious and prone to mistakes. Is there anyway to be able to include one path(Environment Variable) in "Additional Include Directories" that contains all the paths to the "Includes" we need without individually including each and every path or any other solution? Right now, when we create a new solution we have to repeatedly add every solution individually.
Go to view->Other windows->Property manager and then open one of the project nodes and then one node for each of the platforms of interest (that is Debug|Win32, Debug|X64), and right click on the Microsoft.Cpp..User node and select properties.
Now, you can edit this property page just like a project properties but the settings will be applied to all projects (even already created projects).

DLL References in Visual C++

I have had C++ experience but not MSVC.
What I am trying to do is incorporate a .dll from an open source project into my project. The code is available and I have built it. I have the .dll as well as the .lib which as I understand it is required for C++ projects.
Now unfortunately there is no simple "Add Reference", drop my .dll into an include directory and add that to my solution. I have edited the project property pages, the C/C++ Additional Include Directories option as well as adding the .lib as an additional linker dependency. I have created an include directory for the dll and lib inside my solution tree.
My problem is when I try to include the header files from the documentation, VS output spits out error messages. Now I realize that I am using the dll/lib combo and that the .h files are not present in my solution so how do I add the proper includes? I am using QT toolkit also which is working but how I add the other header / dll from the open source library eludes me.
Can someone please point me in the right direction.
You need to do a couple of things to use the library:
Make sure that you have both the *.lib and the *.dll from the library you want to use. If you don't have the *.lib, skip #2
Put a reference to the *.lib in the project. Right click the project name in the Solution Explorer and then select Configuration Properties->Linker->Input and put the name of the lib in the Additional Dependencies property.
You have to make sure that VS can find the lib you just added so you have to go to the Tools menu and select Options... Then under Projects and Solutions select VC++ Directories,edit Library Directory option. From within here you can set the directory that contains your new lib by selecting the 'Library Files' in the 'Show Directories For:' drop down box. Just add the path to your lib file in the list of directories. If you dont have a lib you can omit this, but while your here you will also need to set the directory which contains your header files as well under the 'Include Files'. Do it the same way you added the lib.
After doing this you should be good to go and can use your library. If you dont have a lib file you can still use the dll by importing it yourself. During your applications startup you can explicitly load the dll by calling LoadLibrary (see: http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx for more info)
Cheers!
EDIT
Remember to use #include < Foo.h > as opposed to #include "foo.h". The former searches the include path. The latter uses the local project files.
The additional include directories are relative to the project dir. This is normally the dir where your project file, *.vcproj, is located. I guess that in your case you have to add just "include" to your include and library directories.
If you want to be sure what your project dir is, you can check the value of the $(ProjectDir) macro. To do that go to "C/C++ -> Additional Include Directories", press the "..." button and in the pop-up dialog press "Macros>>".
You mention adding the additional include directory (C/C++|General) and additional lib dependency (Linker|Input), but have you also added the additional library directory (Linker|General)?
Including a sample error message might also help people answer the question since it's not even clear if the error is during compilation or linking.

C++ Project dependencies issue Visual studio 2005

I am working on a dataManagement project that periodically deletes files in a specific folder. The solution has three projects of which, one is the application and the other two are static libraries. Now I want to add one more project which is a static library used for logging. The logging static library project has a header file which the application project refers. When I build the solution, I am getting error as the header file is not found. When I added the logging static library project, I also made the application project dependent on it by checking the appropriate bix in the project dependencies.
Can anyone please help me?
It needs an additional include file path to reference the header file directory...
Project->Properties->Config Properties->C/C++->Additional Include Directories
it doesn't auto pick up the header file paths, it just knows how to link to the project.... Its completely undefined where the header file should be. or even if you have a header file, you can forward reference the thing in the other project if you like!
There are two things you need to do to get a statically linked library working in VS. The compiler needs to be able to find the declaration for the symbols that you're referencing and the linker needs to be able to resolve the full definition. When you add the .lib file to the VS project this meets the second obligation. To meet the first you must include the header somewhere in your source hierarchy before the first reference and you must also tell the project where to find the header files. The dependency settings in VS only set the build order - they will not help here. You need to make sure that the folder that your header files are in is added to the "Additional Include Directories" setting in the project properties, or is one of the global include directories in the main VS Options. You must also make sure that the .lib is added to the linker's "Additional Dependencies" setting.