Issues with including headers from static library - c++

I may be just missing something, but I'm trying to include a MongoDB C++ driver library build into my DLL project. I'm trying to follow this guide
I've tried including the folder in Configuration Properties->Linker->General->Additional Library Directories, and the .lib file in Linker->Input->Additional Dependencies. I've also added the /MT command-line option.
Now here comes my problem - how do I use the files? Do I just use #include "mongo/client/dbclient.h", because this doesn't seem to work (Cannot open source file). I can't find much of any helpful documentation on this subject.
Any ideas?

Related

How to create library that uses some other libraries?

I'm trying to create a graphic library (nothing serious, just to learn stuff). In Visual Studio I have one solution and two projects in it - dll and exe. For window management I use GLFW library. In my own window class I want to have a private memeber of GLFW Window structure. The problem is that my exe project doesn't know what GLFW is - it doesn't know where to find #include <glfw/glfw3>.
My question is - what's the proper way to create such library that uses other libraries? Setting the exe project to include all those libraries doesn't sound like a good idea to me.
Since you are using visual studio, then Microsofts documentation is a great place to get information. https://learn.microsoft.com/en-us/cpp/build/dlls-in-visual-cpp?view=vs-2019 they have a description on DLL’s and how to create them and also how to link DLL’s to projects.
Thanks to #Manuel I figured out how to do it: both - dll and exe projects, have to include libraries' header files.
My solution: in dll I use precompiled headers so all libraries' header files are included in that file with a relative path. In dll project settings I put proper paths so any libraries files will know how to find their headers. What's important is that my exe project includes one header file from my dll and that file include precompiled header so exe project 'knows' everything it needs about libraries.
Thanks again #Manuel for your help!

Linking to Boost in DLL file

I've created a Win32 DLL application that links to the Boost Library. It compiles, and all is well and good, except that if I create another application that references the DLL, it requires that that application link to Boost as well. If I don't link to Boost, I get a "fatal error C1083: Cannot open include file: 'boost/utility.hpp': No such file or directory." Is there any way around this? I'm a noob, so I feel that I may be missing something essential, but I haven't found anything in searching yet. Thanks!
As Biffen said in the comments, that is a compilation error. You project needs to be able to read the Boost header file(s) that your other project used, so you'll have to edit your project settings "additional include directories" so that the location of the Boost header files is accessible.

Having trouble when trying to include boost.serialization into my VS project

So i want to get Boost.serialization into my project but i just want that library from the boost package that you get. I built the boost thing so got i got access to the .lib files for the serialization library.
The ones i got are;
libboost_serialization-vc100-mt-1_55
libboost_serialization-vc100-mt-gd-1_55
libboost_wserialization-vc100-mt-1_55
libboost_wserialization-vc100-mt-gd-1_55
I took these and put them into a new folder and linked my VS project to these files to the additional lib directory.
I also took serialization folder from the boost package and put it in my include folder that is linked to my project.
When i now try to build my app i get these errors;
IntelliSense: cannot open source file "boost/config.hpp"
IntelliSense: cannot open source file "boost/operators.hpp"
IntelliSense: namespace "boost" has no member class "totally_ordered1"
How should i go about to fix these errors? Do i need to add all the .hpp files that the library wants or is there another way around this?
Thanks :)
You mentioned that you built boost and then moved some of the headers into your project. The latter is not advisable - leave the boost includes and libraries where you've installed them and built boost.
In Project ⇒ Properties ⇒ Configuration Properties, add
The toplevel boost directory to the Include Directories (eg., c:\boost)
The directory with the built boost libraries to the Library Directories (eg., c:\boost\lib)
If you still get IntelliSense errors after that add
The "$(ProjectDir)" to the Reference Directories

cannot open file 'SDL2.lib'

I am trying to open sdl2 in my project on Visual C++ 2012 but i keep getting this error:
error LNK1104: cannot open file 'SDL2.lib'
I added the additional libraries and include folder but no luck..
I added the link to the libraries through the linker but i get the same error..
what should i do?
I'm referencing VS 2010, but I've read before that some people have had errors when using the VC++ Directories in their project properties as opposed to the Linker->General->Additional Library Directories.
Unfortunately, there really isn't much more to do besides making sure the directories are linked properly. There really is only one answer to this question. It also may depend on the download of SDL you chose, are you donwloading the Development Library as opposed to the binary?
Watch this video https://www.youtube.com/watch?v=or1dAmUO8k0.
In summary, you want to add the path include folder here: (configuration properties> C/C++ > General> Additional Include Directories),
and add the path of the lib folder here: (configuration properties> Linker > General> Additional Library Directories)
and finally, link .lib file in: linker > input > Additional Dependencies.
It seems like you didn't add your library directory path in VC++ Directories/Library Directories.. You have to link your library directory path (Where you have save you libraries of SDL) in your program. After adding, it will definitely work
I would like to add for others experiencing this problem that its an easy mistake if you are using the Development Library to link to the lib folder. SDL needs you link to either the x86 or x64 folder in the lib folder.
If you run or compile your program before you make those required changes of SDL then you will get this error always.. so first add a c++ file then make those changes and then write something and try to run ..this time it will never give this error
It seems like VS can't find the lib files. There are two ways you can do this. One is to configure the appropriate directories in VS as TwinkleBearDev's article shows. Another is to put the libraries directly where VS would look for them, as my article shows. I don't know if the folders for VS2012 are the same though - might be slightly different.

How to add lib files and headers to a C++ Project

I have been using libcurl in a C++ project.
I have added the libcurl Include and Library directory's to the VC++ Directories and added the .lib file to the Linkers Input Additional Dependencies.
Everything works fine but when I check in my code (TFS) and somebody gets it on another machine they cannot build etc due to not having libcurl installed on their machine or installed in different paths etc.
How do I add all the necessary files to my C++ Solution so that anyone getting the project from source control can build and link without error.
Thanks
The solution I went with was too add the library file to a folder within my solution, then add
$(SolutionDir)libs\curllib.lib
To the Additional Dependencies within Linker->Input
You can not add the library to the solution. you should distribute the library along the source code. Place it in a subdirectory of the project so that it goes along the whole project source. Then configure the path in Additional Library Dependencies. That way the people should be able to link appropriately when building from source.