How to use a library in other c++ code? - c++

I'm trying to use a library in my code.
But as I'm new in c++, I couldn't do that without any errors.
First I copied library in my main file and then in my main code I just included .h files.
When I ran it, it gave me some errors like:
error LNK2019: unresolved external symbol "public: __cdecl library"
The library contains .cpp and .h files of functions.
I'm doing it in Visual Studio 2012.
What should I do to use this lib?

Assuming you are using this library, The documentation to make an installation on Visual Studio is located here.
If this is your first time with C++ then this is a very complex project to start with... Using a library is a complex process as every single one has a diferent installation method.

Related

Include all source file for build

I have C++ project in my Visual Studio. Additionally I placed directory with source files in it in order to use them like library in my main project.
Everything works fine while code browsing. I can define includes of library headers and navigate to functions.
I got problem during project build. I got a lot of linking errors which tells that system can't link to functions from library.
Error LNK2019 unresolved external symbol lv_task_create referenced in function monitor_init testLVGL C:\cpp_test\testLVGL\monitor.obj 1
Error LNK2019 unresolved external symbol lv_tick_inc referenced in function "int __cdecl tick_thread(void *)" (?tick_thread##YAHPEAX#Z) testLVGL C:\cpp_test\testLVGL\testLVGL.obj 1
Error LNK2019 unresolved external symbol lv_task_handler referenced in function SDL_main testLVGL C:\cpp_test\testLVGL\testLVGL.obj 1
Looks like Visual C++ is even not trying to build library.
How to tell Visual C++ to include all library files located in subdirectory in order to build and link to project?
Visual Studio does not include all the files in a directory on its own. You need to explicitly include them (you dont have to do this if you add a file within the Solution Explorer or within Visual Studio). Else it wont be listed to the compiler.
To include them, go to the solution explorer and select "Show all files". This will show you all the files in the directory. Then you can see the unlisted files marked with a red icon. Right click it and hit "Include in project" and the red icon will disappear. After this, the file will be listed as one of the project's file.

OpenCV and Visual Studio 2015: Why is including the static library not working?

I'm trying to set up a VS2015 solution I have with OpenCV 3.0.0, and I'm trying to do so using static libraries only.
Header files: the OpenCV header files are included correctly and I can reference them in my source files without issue.
Libraries: the static library file that was created for me when I used CMake to build OpenCV (called "ippicvmt.lib") is included correctly, and loads without issue.
Using OpenCV in code: when I try to use OpenCV classes/functions in my solution, I get linker errors when building similar to
LNK2001: unresolved external symbol "public: virtual double __thiscall cv::VideoCapture::get(int)const
I can right-click and choose "Go to definition" on my use of this function and it opens videoio.hpp and shows the declaration of the virtual method. The linker error I see is likely caused by the inability for visual studio to find the actual implementation of the method in the static library I have included in my solution.
It is my understanding that the only .lib file I need to include is the one static library file. That is all I have included right now.
Does anybody know why VS can't find the implementations of this code in the OpenCV static library?
I fixed my issue by disabling the flag for building with shared libs in CMake, after that way more .lib files show up in the sharedlib folder in my install. I added each .lib file I wanted to use to my additional dependencies in my project properties and my project built.

Compiling an Octave mex file through Visual Studio 2013

I just switched to Octave from Matlab and would like to continue to compile mex-files as a DLL through visual studio.
I have a project which creates a dll and exports the mexFunction as previously. I also include the mex.h file found in Octave but I have trouble linking.
Currently I get a linking error stating:
error LNK2019: unresolved external symbol __imp_mexPrintf referenced in function mexFunction
I understand why but I don't know what to include to resolve this issue.
Can anybody help?
Thanks
Henrik
The files are found in:
C:\Octave\Octave-3.8.2\lib\octave\3.8.2
and I used liboctave.dll.a and liboctinterp.dll.a

OGRE error LNK2001: unresolved external symbol

I'm trying to get some OGRE sample to compile in VS 2013 but I keep getting the same error no matter what I do:
error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::system_category(void)"
The OGRE SDK comes with the boost library. Unfortunatly it is not compatible with VS2013 so I've downloaded the last version compiled using VS2013. You can find it here
The "additional Include Directories" and "additional Library Directories" are properly setup.
The error state that you are using a symbol that is declared, but not implemented, boost::system::error_category is a method of boost, that various libraries use when managing errors, it belong to the system library, the implementation of this method is in [BOOST_ROOT]\boost\libs\system\src\error_code.cpp.
The most probably cause is that your are including the OGRE's library or part of the library that include some boost's libraries that use this method.
A lot of libraries from boost are header only, but this specific library system are not, it need compilation of this .cpp: two possible fixes are compiling an .LIB or .DLL from boost (see Prepare to Use a Boost Library Binary for more info about this) and using this in your project (could be better if you would be using a lot of libraries from boost that are not header only) or the most easy fix: including the error_code.cpp file in your project and compiling again.

C++ project compiles as static library but not dynamic (Visual Studio)

I'm a little new to c++ in visual studio, and I'm trying to compile a massive C++ project with Visual Studio. I've gone through and added all source and header files to my project and also updated all of the include paths in the project properties.
If I have the type of project set to "Static Library (.Lib)" the project will compile without error and I'll have a nice fatty .lib file.
If I change the project over to a "Dynamic Library (.dll)" The project no longer compiles and fails on linking errors.
Here's an example of one:
Error 27 error LNK2001: unresolved external symbol "char const * __cdecl Project::toString(enum Project::compMode)" (?toString#Project##$$FYAPBDW4compMode#1##Z) H:\repo.project\user\tool\component.obj tool
Any help or background on what might be happening here?
Check if you defined the following member function
char const* Project::toString(Project::compMode)
When you compile as a static library an unresolved symbol is not an error, because it can be resolved later when you link with other code.
You may have forgotten to add some .cpp file to your project.