I started with learning C++ a few days ago and I would like to get some data to make it more funny. I found a powerful C++ library called Unirest that can help me to get data from many APIs and after practice the basics :)
I don't know how to include libraries into my project. I fond some videos about how to do it so I just created libs
folder (like i always do when I'm programming in PHP) and I copied library files. After I included header file UNIRest.h
into my source and added the libs
directory into VS+ Directories option in Project Properties - Configuration Properties - VC+ Directories. Everything is still OK. But when I opened the header file UNIRest.h
the problem appeared:
#import "UNIHTTPRequest.h" #import "UNIHTTPRequestWithBody.h" #import "HttpRequest/UNISimpleRequest.h" #import "HttpRequest/UNIBodyRequest.h" #import "HttpResponse/UNIHTTPBinaryResponse.h" #import "HttpResponse/UNIHTTPJsonResponse.h" #import "HttpResponse/UNIHTTPStringResponse.h"
All of those macros are underlined and compilation failed with message:
fatal error C1083: Cannot open type library file: 'libs\unirest\unihttprequest.h': Error loading type library/DLL.
Could you please help me? Hope it's not just a stupid question because I tried to make it works whole afternoon :(
Run OleView.exe from the Visual Studio Command Prompt and use File + View Typelib, select that DLL. You need to see the content of the type library, decompiled into IDL. You can also see it in VS itself, use File + Open + File and select the DLL.
For adding libraries, this is very simple (if that's what you mean) Project -> properties -> configure properties -> Linker -> Input -> additional libraries. Go stand on one of the libraries in there and press enter.
Start Visual Studio Code. In the Open Folder dialog, create a ClassLibraryProjects folder and click Select Folder (Open on macOS). Open the Terminal in Visual Studio Code by selecting View > Terminal from the main menu. The Terminal opens with the command prompt in the ClassLibraryProjects folder.
Typically you need to do 5 things to include a library in your project:
1) Add #include statements necessary files with declarations/interfaces, e.g.:
#include "library.h"
2) Add an include directory for the compiler to look into
-> Configuration Properties/VC++ Directories/Include Directories (click and edit, add a new entry)
3) Add a library directory for *.lib files:
-> project(on top bar)/properties/Configuration Properties/VC++ Directories/Library Directories (click and edit, add a new entry)
4) Link the lib's *.lib files
-> Configuration Properties/Linker/Input/Additional Dependencies (e.g.: library.lib;
5) Place *.dll files either:
-> in the directory you'll be opening your final executable from or into Windows/system32
In code level also, you could add your lib to the project using the compiler directives #pragma.
example:
#pragma comment( lib, "yourLibrary.lib" )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With