How to use a C++ library method in a visual studio project - c++

I'm trying to test a method from a static library that I created. The method from the library just prints something to the console. I have added the directory in the properties tab and added the linker input. However, the project still does not recognise the library. Would anyone be able to help. Any help is appreciated.
Libary header:
void TestLiabry();
Libary method:
void TestLiabrys()
{
cout << "Hello" << endl;
}
Project I want to use the method in:
#include <iostream>
#include "TestLibary.h"
int main()
{
std::cout << "Hello World!\n";
TestLiabry.TestLiabry();
}
I added the library in the linker like this:
Linker -> Input -> Additional Dependencies -> C:\Users\jorda\Downloads\TestLiabry
It pops out this error:
Severity Code Description Project File Line Suppression State
Error MSB6006 "link.exe" exited with code 1104. Project1 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets 1010
And this lnk error:
Severity Code Description Project File Line Suppression State
Error LNK1104 cannot open file 'C:\Users\jorda\Downloads\TestLiabry.obj' Project1 C:\Users\jorda\Downloads\Project1\LINK 1

There seemed to be an error in my linking of the path to the library where I didn't include the library .lib. Only include the path and not the path and lib file in the directory.

Related

How to compile program that uses boost::filesystem?

I'm trying to compile a sample program that uses boost::filesystem:
#define BOOST_FILESYSTEM_NO_DEPRECATED
#include <boost/filesystem.hpp>
int main()
{
boost::filesystem::path full_path(boost::filesystem::current_path());
std::cout << "Current path is : " << full_path << std::endl;
}
I've downloaded and compiled boost 1_72, added my_path_to_boost to include directories and my_path_to_boost\stage\lib to include lib directories
When I try to compile the program, I'm getting following error:
Severity Code Description Project File Line Suppression State Suppression State
Error LNK1104 cannot open file 'libboost_filesystem-vc142-mt-gd-x64-1_72.lib' current-path D:\My Projects\filesystem\current-path\LINK 1
I have verified that libboost_filesystem-vc141-mt-gd-x64-1_72.lib is located in my_path_to_boost\stage\lib.
I'm using Visual Studio 2019
What am I missing? Is there any way I can see where VS is looking for the file?

VS2019:fatal error C1083 Cannot open header file: 'opencv.hpp'

It is all fine when I was writing the code, that is, when I included the header file "opencv2/opencv.hpp",and VS2019 can indeed "see" it,in other words, I can use the class that is in the opencv.hpp, but only when I complied the project,c1083 occurred
before i added the function DrawLine(),i compiled for times,with no err.and then i added the function DrawLine(..),error occurred
this is the total source code
a.ha.cpp
//a.h
#include<opencv2\opencv.hpp>
using namespace cv;
class Canvas{
Mat mat_canvas;
void Init(){
mat_canvas.create(1024,1024,CV_32FC3);
}
void DrawLine(float ax,float ay,float bx,float by);
}
//a.cpp
#include"a.h"
void Canvas::DrawLine(float ax,float ay,float bx,float by){
cv::line(this->mat_canvas,Point2f(ax,ax),Point2f(bx,by),Scalar(1,1,1));
}
error msg was:
fatal error C1083 Cannot open header file: 'opencv.hpp': no such file or dir
i know i can create a new solution and move my old solution to it,but it takes time,and i can't actually know whether this issue will happen again in my new solution
Any answer will be helpful
Actually there are most of the time possibility of missing "Additional include directory path" or wrongly setup.
Where to find in Visual Studio:
To set this compiler option in the Visual Studio development environment
Open the project's Property Pages dialog box. For details, see Set
C++ compiler and build properties in Visual Studio.
Select the Configuration Properties > C/C++ > General property page.
Modify the Additional Include Directories property.
Visual Studio 2019 C++ Project configuration
Example project setup is described in below link:
Example setup

cannot open include file 'Graphics.hpp' no such file or directory ,additional include for visual studio not working

i m trying to use sfml in my project using visual studio 2019. Following sfml documentation to perform setup for visual studio i have performed all the action required
i have included include folder in c/c++/additional include directory and also provided path for lib folder in linker setting and also provided additional dependencies in linker/input
but
#include <iostream>
#include <SFML/Graphics.hpp>
int main()
{
std::cout << "i cant tolerate" << std::endl;
return 0;
}
this code shows above mentioned error ,
cannot open include file 'Graphics.hpp' no such file or directory
it seems like include path is not working
how can i solve this issue
i tried many times but got same result
if anyone facing the same problem please check the platform in the project/properties win32 worked for my particular problem

Include zxing in C++ project

I try to integrate zxing in an other C++ project. I'm using Visual Studio 2012 with Windows 7.
I would like to run the sample code from the zxing repository:
zxing example
If i compile my project i get an error:
zxing_integration.obj : lnk2001 unresolved external symbol
zxing_integration.exe fatal error lnk1120 1 unresolved external symbol
what I've done so far:
create an win32 console application named zxing_integration in the folder ...\workspace
create an folder ...\workspace\git and clone the zxing repository
create an folder ...\workspace\zxing-cpp\build and build the zxing project with the command line prompt cmake ..\workspace\git\zxing-cpp -G "Visual Studio 11 2012" (i think this step is not necessary)
Added under project settings->C/C++ -> additional include directorys (all configurations) the following pathes: ...\workspace\git\zxing-cpp\core\src and ...workspace\git\zxing-cpp\cli\src
After these steps nothing is red underlined or marked in Visual Studio, so i think the source files can be found. If i build the project i get the two errors. i think that the linker needs .lib files, but i can not found zxing libs in the project. Do i have to build the lib files?
It is strange that the error appears in line 258 source = ImageReaderSource::create(filename); and not in line 256 Ref<LuminanceSource> source;. It seems that LuminanceSource can be found.
Ref<LuminanceSource> source;
try {
source = ImageReaderSource::create(filename);
} catch (const zxing::IllegalArgumentException &e) {
cerr << e.what() << " (ignoring)" << endl;
continue;
}
For anyone stumbling over this dated question: there is a 'new' c++ implementation with lots of improvements compared to the upstream Java project: ZXingCpp
It can be built on Windows/macOS/Linux/Android/WASM.

C++ LInker error (Visual Studio C++ 2010)

I tried to create empty project for Visual Studio.
// OpenGL1.cpp : main project file.
// #include "stdafx.h"
#include "windows.h"
#include <GL/gl.h>
#include <iostream>
using namespace System;
int main()
{
std::cout << "Hello World" << "\n";
return 0;
}
Having configured these dependencies:
opengl32.lib;glu32.lib;olepro32.lib;%(AdditionalDependencies);C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl;
And I got this error:
.NETFramework,Version=v4.0.AssemblyAttributes.cpp
LINK : fatal error LNK1104: cannot open file 'C:\Program Files\Microsoft SDKs\Windows\v7.0A\Include\gl.obj'
Can you explain why this happens and how to remove the error?
The "dependencies" refer to the filenames of libraries which the linker should use, not to include paths. Include paths are for the compiler, not for the linker.
You must first tell the linker where to find the OpenGL library file:
http://msdn.microsoft.com/en-us/library/1xhzskbe%28v=vs.100%29.aspx
And then, as a dependency, you specify only its name, not a full path. In this case, opengl32.lib.