Linking External C++ Library (Exerces) in Visual Studio - visual-studio

I am working on a C++ project with
#include <xercesc/sax2/ContentHandler.hpp>
#include <xercesc/sax2/Attributes.hpp>
#include <xercesc/util/XMLString.hpp>
On the offical xercesc website, they have the following instructions:
I downloaded the distribution file
Opened the xerces-all.sln file in VS2017 and pressed build
Then I opened my project in VS2017, went to properties->Linker->Input->Additional Dependencies and added xerces-c.lib
However the VS2017 complier still can not find the included xerces files

The included documention you are looking at is titled "Building on Windows" so if for beuiding the library, not on using it afterwards.
You need to add the path to the include files in your project in C/C++ -> General ->Additional include directories
And for the library, you may need to add to the Additional Library Directories

Related

Cannot open include file: No such file or directory, but it exists in Additional Include Directory

When trying to build a C++ project in Visual Studio 2022 I get:
Cannot open include file: 'boost/asio.hpp': No such file or directory
Include line causing error:
#include <boost/asio.hpp>
But I did include the path to this file through Additional Include Directories already.
In my user's desktop directory x64-windows\include folder contains boost folder, which contains the included asio.hpp file. It also contains asio folder.
Edit: Changing <boost/asio.hpp> to "boost/asio.hpp" doesn't help.
This fixed it for me:
.\\vcpkg.exe integrate install
it returned:
Applied user-wide integration for this vcpkg root.
All MSBuild C++ projects can now #include any installed libraries.
Linking will be handled automatically.
Installing new libraries will make them instantly available.
Now the project compiles without any problem.

Compiling a cpp file on linux with Windows libraries

I would like to solve this issue once for all, what is the best best to compile a .cpp file that uses windows libraries (to create a exe file).
For instance I have this cpp starting with:
#include "stdafx.h"
#include <Windows.h>
And I get
stdafx.h: No such file or directory
Windows.h: No such file or directory
I know for instance that stdafx require Visual C++ on Windows, but I want to compile it on Linux, how would you do ?
Thanks a lot
The short answer is you cannot build a Windows executable on Linux. But you can download the free Visual Studio Community Edition to build it on Windows.
stdafx.h is a header file in your project. It is used by Visual Studio's pre-compiled headers feature. If you use a predefined project template, Visual Studio will auto-generate stdafx.h and mark it for pre-compilation. You then include the common C++ headers, e.g. STL, in stdafx.h and include stdafx.h in each of your source code files.
When you are not using Visual Studio stdafx.h is a convenient place to pull in the standard headers for runtime libraries but serves no other purpose.
windows.h is the header file for Windows runtime APIs. The Windows APIs and hence the headers are not available on Linux. If you want to build an executable on Linux to run on Linux then you must replace Windows APIs with the Linux equivalents.

How to include png++/libpng for Visual Studio

can anybody help me how to use png++/libpng in a Visual Studio Project?
For Linux there are several tutorials and examples, but for the usage in a Visual studio project I found no help.
My CMakeLists.txt-file looks this way:
# project
cmake_minimum_required (VERSION 2.6)
project (libviso2)
# directories
set (LIBVISO2_SRC_DIR src)
# include directory
include_directories("${LIBVISO2_SRC_DIR}")
# use sse3 instruction set
SET(CMAKE_CXX_FLAGS "-msse3")
# sources
FILE(GLOB LIBVISO2_SRC_FILES "src/*.cpp")
# make release version
set(CMAKE_BUILD_TYPE Release)
# demo program
add_executable(viso2 ${LIBVISO2_SRC_FILES})
target_link_libraries (viso2 png)
Using CMake GUI and the above CMakeLists.txt-file I can generate a Visual Studio Project that works fine for itself until the png++-algorithms are handled in the code (build error). So basically my problem is that I have no experience in CMake and png++/libpng.
I have two folders downloaded from the web, one folder png++ and one folder libpng.
In these two folders there is all the code for the two libraries.
So my question is:
Could anybody explain to me how to arrange/include these two folders in a Visual Studio project producing no error, this could be a very simple project starting:
#include "png++/png.hpp"
using namespace png;
How would I edit the CMakeLists file in order to build a Visual studio project in which the png++ and libpng folders are correctly included so as to make it feasible to use the png++ code?
Thank You in advance for any help!
png++ is a C++ wrapper for libpng library, so it only has header files.
what you need to do is to compile libpng and its dependency(zlib).
and include header files of png++, libpng and zlib, add library of libpng and zlib.
That's all you need, I ran libviso2 successfully on Windows, good luck!

Problem in configuring opencv 2.2 on windows 7 (64-bit):

I have windows 7 (64-bit) and I am trying to configure opencv 2.2 for Microsoft visual studio 2010, I followed the instructions given in the book OpenCV 2 Computer Vision Application Programming Cookbook , but it’s not working, I performed the following steps:
Compile opencv 2.2 using cmake, (source code: C:/OpenCV-2.2.0, where to build binaries: C:/OpenCV-2.2.0/build)
Open OpenCV.sln (which is made as a result of compiling by cmake in the folder C:\OpenCV-2.2.0\build), this is opened in visual studio, I build it (result of build: no errors, few warnings).
Add new property sheet to my project, and in VC++ directories, under the “Include Directories “ I give the path of C:\OpenCV-2.2.0\include\opencv and under the “Library Directories” I give the path of my lib files i.e C:\OpenCV-2.2.0\build\lib\Debug.
Within the linker tab under the Input, included the following Additional dependencies:
opencv_core220d.lib
opencv_highgui220d.lib
opencv_features2d220d.lib
opencv_calib3d220d.lib
According to the instructions on the book now everything should be configured correctly, but when I include header files,(after typing (Hash)include (angle bracket)) the intellisense only gives:
#include <cxcore.h>
#include <cv.h>
but instead it should had displayed
#include <opencv2/core/core.hpp>
and when I write
#include <opencv2/core/core.hpp>
it gives me error cannot open source file
“opencv2/core/core.hpp“ ,
if I include
#include <cv.h >
I got 11 errors:
1. IntelliSense: cannot open source file "opencv2/core/core_c.h" c:\opencv- 2.2.0\include\opencv\cv.h 63 1
2. IntelliSense: cannot open source file "opencv2/core/core.hpp" c:\opencv-2.2.0\include\opencv\cv.h 64 1
3. IntelliSense: cannot open source file "opencv2/imgproc/imgproc_c.h" c:\opencv-2.2.0\include\opencv\cv.h 65 1
4. IntelliSense: cannot open source file "opencv2/imgproc/imgproc.hpp" c:\opencv-2.2.0\include\opencv\cv.h 66 1
[The remaining errors are similar to the above errors.]
I have not included anything under the C/C++ -> General -> Additional Include Directories
in the property sheet, is there any need to include anything there ???
Can anybody please tell me, what I did wrong in the configuring process?
Is there any guide available specifically for configuring opencv 2.2 on windows 7 (64-bit) on visual studio 2010?
Maximus solution sounds like a spray and pray attempt.
I cleanly only added [opencvDir]\include to my visual studio includes and it all worked really fine.
Including with your syntax
#include <opencv2/core/core.hpp>
works just fine, thats how i do it. The rest of the steps I did was exactly what you described, except that I have different projects with different parallel opencv installations, so i did not add OpenCV to my global environment variable "PATH" but rather than that I selectively use OpenCV for each project by selection Project Properies (right click project, select properties) => Debugging => "Environment" : Set to PATH=$(SolutionDir)Dependencies\opencv2.2\x86\bin" (in my case), and "merge environment" to "yes"
That is necessary so opencv finds its DLLs in case you link non-static.
Hope that helps :)
You need two include directories. For me it was, C:\OpenCV2.2\include and C:\OpenCV2.2\include\opencv
Try including all directories in C:\opencv-2.2.0\modules\module_name\include
For example in your case it could be
C:\opencv-2.2.0\modules\core\include\
C:\opencv-2.2.0\modules\imgproc\include\
and many more. You should use comand line to get that list of directories in the C:\opencv-2.2.0\modules. And after each add include.
I don't know why does this happens..
In my property page,
in C/C++ -> Addictional Include Directory
I was using "%OPENCV_DIR\build\include"
Replacing by the real path fixed the issue with intellisense:
"C:\opencv\build\include"
I am running opencv 2.4.2 and Visual Studio 2010 SP1.

How to exclude .lib file from linker command line argument in VC++

I am compiling a vc++ program which is showing below error
error LNK1104: cannot open file 'D:\Visual Studio 2010\Projects\credentialproviders\Win32\Debug\Helpers.lib'
how i can remove that Helpers.lib file reference from linker command line argument because in project settings->linker->commandline its in readonly mode and I can't edit this to remove that line. I am using Visual Studio 2010.
thanks
Search the .vcproj file, and the project source code for "Helpers.lib". There are a couple places it can get linked in, and this is the simplest way to find it.
Otherwise, look for:
Project properties -> linker -> inputs
In the solution explorer, see if the .lib is included anywhere in the project tree.
Anywhere in the source code, #pragma comment(lib, "helpers.lib")
If Helpers is a project in your solution, check project dependencies for the project. By default, thisk linking is done implicitly if the project depends on it.
if this lib is not referenced in Linker->Input->Additional Dependencies, so check Project Dependencies, and remove any dependency on porject Helpers. also it's possible that this linking is done from code by #pragma comment(lib, "Helpers)
I don't really think the above answers it properly. I just had this same problem and the way to fix it is to go to View->Property Manager. double click Microsoft.Cpp.Win32.user and go to Linker->Input. There you can edit out the additional dependencies that were previously read only. Do it for both debug/release versions if needed.

Resources