How do I use cURLpp with Visual Studio? - c++

I'm using VS 2019, have downloaded all the cURLpp headers, put them and the cURL headers in an include folder and added this include directory under Project Properties -> Additional Include Directories. When I try to build example00.cpp from the cURLpp site, I get errors saying I have an unresolved external symbol. I've never used a third party library with C++ before, so please explain like I'm an idiot. Should I have a dll or lib file?

I use vcpkg to install curlpp, and I find that my project configuration in visual studio is x64, if I use x86 curlpp it will get build error, I need to use x64 curlpp then build sucess.
This is the include step:
Run cmd command: vcpkg install curlpp:x64-windows
goto Project > Configuration Properties -> Linker -> General -> Additional Library Directories, add yourVcpkgFolderPath\vcpkg\installed\x64-windows\lib\
goto Project > Configuration Properties -> Linker -> Input -> Additional Dependencies, add curlpp.lib
Then build the project, it should build success.

Related

Questions about third-party library(oat++) configuration in visual studio

As a beginner, I want to use oat++ as a third-party library in visual studio, but I encountered some configuration problems.
First I downloaded the source file of the oat++ project and opened it in visual studio and cmake and install.
Then I created a new project in visual studio and started running the first example of the official website.
First of all, it need to configure the preprocessing, I will configure the Include directory first.
What I did is:(my project name is web4)
Project -> Web4 properties -> configuration properties -> VC++ Directories
set the Include Directories include C:\Users\13925\Documents\cpp\oatpp\out\install\x64-Debug\include\oatpp-1.2.5\oatpp
That is great. The compiler can find the #include "file"
After that I'm having trouble,An error occurred when I tried to compile.
Error LNK2019 unresolved external symbol __imp_WSAStartup referenced in function....
By searching for information, it is found that the cause of this problem is that the related library is not included.
But I tried the online method and it didn’t solve the problem,so ask for help here.
The online approach is like this:
Project -> Web4 properties -> configuration properties -> VC++ Directories
set the Library Directories include C:\Users\13925\Documents\cpp\oatpp\out\install\x64-Debug\lib\oatpp-1.2.5
In C:\Users\13925\Documents\cpp\oatpp\out\install\x64-Debug\lib\oatpp-1.2.5 has three files:oatpp.lib、oatpp-test.liband a .hfiles.
Project -> Web4 properties -> configuration properties -> Linker -> Input
set Additional Dependencies include oatpp.lib and oatpp-test.lib
Compile after completing the above four steps and find that the problem is still not solved.
And the problen still unresolved external symbol.
I would be very grateful if you are willing to help.
As far as I'm concerned, the problem is you are not linking against the Ws2_32.lib library. To fix this you could try to add that to your additional dependencies tab of linker/Input settings for your project. And you could also try to add: #pragma comment(lib, "Ws2_32.lib")
Best Regards,
Jeanine

How to add a library to my project in a visual studio 2019?

I needed to use zydis library in my VC2019 cpp project.
I have no idea how can I add it to my current project - I downloaded it from github.
There is msvc folder, inside I can find .sln file, some header files and .vcxproj files - what should I do, to just include it into my project and use it?
It can be done by adding a reference to the DLL file.
In Visual Studio, right click on the project, Add Reference. Give the path to the DLL file and add it to the project.
First, I suggest that you could download and install Zydis using the vcpkg dependency manager. The method is easy and convenient.
If you don't use vcpkg, you could follow the steps below.
Open the Zydis.sln in msvc with VS2019.
Copy files in include/Zycore, put them in zydis-master\include\Zycore. Because I find that there should be missing files when I compile Zydis.sln.
Right click Zydis, set Visual Studio 2019(v142) in Properties->General->Platform Toolset.
Compile it, and you will find Zydis.lib in zydis-master\msvc\bin\DebugX64.
Then, you could copy include floder and lib in your program floder.
You could set VS:
Right-click the project, select Properties->Configuration
Properties->C/C++->General, find the Additional Include Directories and set the directory.
Properties -> Configuration Properties -> Linker ->
General, find the Additional library directory in General, and set the lib.
Properties -> Configuration Properties -> Linker -> Input,
find Additional Dependencies and input the lib name.
Besides, you could set five build configurations.

Issue setting up gmock on visual studio 2019

I'm trying to setup gmock on visual studio 2019.
I have my folder structure as below
Here i have configured my project with source code(Gmock_project) as a static library. And i have made runtime library as Multi-threaded DLL (/MD). I'm also not using any any precompiled headers.
Then for the unit test project i have done the following properties.
1) Created a new project from the Google Test template (Gmock_Sample).
2) Installed the latest gmock NuGet package from Google (currently v1.10.0).
3) Added the file gtest_main.cc to the project.
4) I have disabled the precompiled headers for gtest_main.cc, gmock-all.cc and gtest-all.cc.
5) I have added the reference of the Gmock_project to the test project.
6) I have included the path of the Gmock_project in VC++directories -> Include directories.
7) I have made runtime library as Multi-threaded DLL (/MD).
8) I have added the path of Gmock_project.lib in Linker -> General -> Additional Library Directories.
9) I have included the Gmock_project.lib in Linker -> Input -> Additional Dependencies.
Whenever i'm building Gmock_Sample i.e. test project i'm getting error
2>test.obj : error LNK2005: main already defined in gtest_main.obj
2>E:\GMock\Gmock_Sample\Gmock_Sample\x64\Release\Gmock_Sample.exe : fatal error LNK1169: one or more multiply defined symbols found
2>Done building project "Gmock_Sample.vcxproj" -- FAILED.
========== Rebuild All: 1 succeeded, 1 failed, 0 skipped ==========
What could be the issue in configuration?
I fixed this issue today by doing a CMAKE Build for Windows using the googletest repository and then adding the static .lib files and headers into my project.
Here are the steps:
1.Clone googletest Repository -> Git-Repository
2.Download CMAKE for Windows. -> CMAKE For Windows
3.Install CMAKE, Don't forget to create the System Variables to call it from the CMD.
4.Go to the cloned Repository Folder.
5.Create a folder called "build".
6.Create a folder in your solution application called "googletest-package" -> the .lib files and headers will be exported here.
Run the following command in the cmd or powershell.:
cmake -G "Visual Studio 16 2019" -DCMAKE_INSTALL_PREFIX=C:\YourSolutionFolder\googletest-package ..
In your build folder you will find now the googletest-distribution.sln -> Open the file with a double click.
In Visual Studio build the ALL_BUILD Project and then the INSTALL Project this will move the headers and .lib files to the googletest-package folder in your solution.
--First Stage Finished!
For the Second Stage we need to do the following since we already have the headers and static libraries its time to link them to the project we want to test.
Create a new c++ project in the solution you are trying to test.
-> Richt Click Solution -> Add -> New Project-> Google Test -> Configuration as Static Library and Link statically.
We need to remove first the googletest NU Package installed automatically from the test project to avoid duplicates and clashes with our own googletest build.
GO TO -> Tools -> NUGet Package Manager -> Manage NuGet Packages for Solution -> Uninstall Microsoft.googletest.vXXX...
Now Add the Include Folders and link the .lib files to the test project as follows:
-> Right Click in the test project -> C/C++ Tab -> Additional Include Folders
Add the following includes...
"YourSolutionFolder\googletest-package\include"
"YourSolutionFolder\googletest-package\include\gmock"
"YourSolutionFolder\googletest-package\include\gtest"
Now Time for the Linker Tab...
-> Linker -> General -> Additional Library Directories -> Add "YourSolutionFolder\googletest-package\lib"
Add the .lib objects as follows:
Linker -> Input -> Additional Dependencies -> Add the following...
"gmockd.lib;gtestd.lib;mock_maind.lib;gtest_maind.lib"
5.In your pch.h file add the following line #include "gmock.h".
You should now be able to build all projects and run tests with mocks!
I hope this helped allthough is a little bit long I think it could be automated.

How to add Include directories in Visual Studio while cross-compiling to a Raspberry Pi?

I'm working on a c++ project on my Raspberry Pi. I'm using Visual Studio 2017 to cross-compile the project to my Raspberry.
But when I try to compile the project, I get the error"cannot open source file" in lots of header files.
I already managed to compile simple projects, but now I need to Include Directories and I don't know the proper syntax to set, on Visual Studio's project properties page, the Include Directories to tell the compile where the header files are stored.
For the PCL library, e.g., I was able to include directories using '$(INCLUDE_PCL)'.
But when I try to include pi's directory '/usr/Include/ni' I can't correctly set the absolute path. Here's an screenshot of my properties page (https://ibb.co/G2dszrx). I haven't set the Linker directories yet, since I'm currently getting errors on the compiling phase.
Does anyone knows how to set absolute path to include directories correctly?
EDITED:
Trying to figure this out, I created a new project (Proj) in which I include the file 'try.cpp' stored in the raspberry's "home/pi/projects" folder. This project is in the "/home/pi/projects/Proj" folder.
In the project property page, I have:
Configuration Properties>General>Remote Build Root Directory --> ~/projects
Configuration Properties>General>Remote Build Project Directory --> $(RemoteRootDir)/$(ProjectName)
C/C++>General>Additional Include Directories --> $(RemoteRootDir)
When I compile the project this path gets created correctly, and the project is saved at the correct place, even if go further into more folders in the remote build project directory, but it can't find the include file "try.h".
How can Visual Studio know where to save the project using '$(RemoteRootDir)', but is not able to add that path include directory?
After some searching I managed to correctly add the Additional Include Directories, and Additional Libraries.
Firstly I was also using OpenNI, to work with the PCL. After many tries, I discovered that OpenNI was not correctly installed. So I managed to install it with apt-get.
Secondly, If you want to include the "/home/pi/someDIR" directory at the Raspberry device, just add "/home/pi/someDIR" to Visual Studio's additional include directories.
For you still trying to achieve this, Merlyn Oppenheim, from visual studio, set up a sample project using VS 2019 and Raspberry PI template -> https://github.com/merlynoppenheim/sample-rasp-inc-headers
For this sample project the Visual Studio properties page should have:
C/C++ -> General -> Additional Include Directories = '/home/pi/projects/vcpkg/packages/sqlite3_x64-linux/include;%(AdditionalIncludeDirectories)'
C/C++ -> Linker -> General -> Additional Library Directories = '/home/pi/projects/vcpkg/packages/sqlite3_x64-linux/debug/lib;%(AdditionalLibraryDirectories)'
C/C++ -> Linker -> Input -> Library Dependencies = 'wiringPi;sqlite3;pthread;dl'

Issue including curl lib in Visual Studio 2015 for c++ program

I'm having some unknown issue trying to use the curl library in my c++ application.
This is what I have done so far:
Download latest version of curl
Build curl "nmake /f Makefile.vc mode=dll VC=12" - i get the following folders and files:
bin -> libcurl.dll
include -> curl -> bunch of .h files
lib -> libcurl.lib
Next I open Visual Studio 2015 Update 3 and go to Configuration Properties:
C/C++ -> General -> Additional include directories -> ..\curl\include
and
Linker-->Input->Additional Dependencies--> ..\curl\lib\libcurl.lib
and then copy the .dll to the debug folder.
This procedure has worked for me for another library but for CURL i am getting the error message:
"Error LNK1104 cannot open file '..\curl\libcurl.lib'"
I can #include "curl\curl.h" without any errors. Problem seems to be with the lib file. I have been looking all over the web for 6 hours, I'm totally lost.
The general preferred usage in VS is to specify additional library directories (Linker->General->Additional Library Directories) where you specify the path of your curl lib.
Then add the libcurl.lib to your additional linker dependencies.