C++ Project dependencies issue Visual studio 2005 - c++

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.

Related

Eclipse Include Paths outside Project Directory

I am having an issue including files outside my project directory. I have a project in eclipse with some header files outside of the project that need to be linked to my project. I have added the path to C/C++ General for the header files and included them in my code. It seems like only one of the files can be seen and the other file I am getting an unresolved inclusion error. Does anyone know how to fix this?
The following is thanks to comments from #user7860670 -- you can see more commentary in eclipse: including a path outside of the project
Short form:
Use system variables.
For include directories relative to your workspace, use something of the form "${workspace_loc}/../my_includes".
For include directories relative to your project, use something of the form "${project_loc}/../my_includes".
Note that in some IDEs, the system variables may be named differently.
See eclipse: including a path outside of the project for more details.

Using header files with multiple projects in same solution

I'm using C++ and visual studio 2015. I've created 2 projects in 1 solution. The first project is a static library and the other a DLL. I want to include one header file from the static library to use it in the DLL. I tried specifying the path to the header file with - Project->Properties->C/C++ -> General -> Additional include directories but it doesn't work. When I try to include the header file I get a red underline saying "cannot open source file "SomeHeaderFile.h".
Thanks for the help.
Thanks for the tips but I found out how to make it work. The DLL is in a extra folder. All I had to do was #include "../../TheHeaderFileThatISpentHoursTryingToGet.h". I deleted the reference in the additional include directories path and it still works. I always thought that it made sense for files from different projects in the same solution to be accessible throughout all the projects. Thanks again.

Is there a way to link classes from different solutions together in Visual Studio?

I have multiple solutions for different project I have worked on but the project I am currently working on rely on a class from a previous solution. I was wondering if there was an easy way to link these solutions together so I have access to all the previous classes.
The most maintainable way to do this is to add the source project's header file directory to your target project's include list.
In the project's configuration properties page, go to:
C/C++ -> General -> Additional Include Directories.
If the source project is compiled into a library, dynamic or otherwise, you will need to link with the corresponding .lib file.
To do this, go to "VC++ Directories" and add to the "Library Directories" field the path containing the .lib file.
Note that you can also add your source project's header directory in this page as well.
After that, go to Linker->Input and add your library's .lib file name.
You will now be able to #include<your_header_file.h>.
Note that you will need to be careful about the choice of directory, as files with the same names as standard or platform-specific headers will cause problems.
EDIT:
I do not know of a way to avoid editing the VC++ Directories page in the project's property page to add a library directory. Why is this a problem? Things like Intel's C++ composer like to step all over these fields (you have to let it make a mess, then you can clean it up).

Sharing files between projects in Visual C++ 10

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.

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.