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

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.

Related

Install OpenCV without lib file

I have a version of OpenCV built with MinGW and I'm trying to include it in a Visual Studio project. I have the dlls and the header files, however no lib files were provided. Only dll.a files. I tried pointing the linker additional dependencies setting to the dll.a files however I still get unresolved external symbol errors.
How do I use this version of OpenCV if it doesn't have the lib files?
Note: I should mention, I'm trying to use this specific build because it is x86, which is what I need for this project, and the official site doesn't seem to provide x86 builds.

How to use libpng in Visual Studio?

I am using boost generic image library and it requires libpng. I built libpng and obtained the files libpng.lib, zlib.lib and libpngd.lib. When I tried to compile my project, Visual Studio gives a fatal error
fatal error LNK1120: 21 unresolved externals
with a bunch of unresolved external symbols like _png_set_sig_bytes and _png_read_row. What's going on here and how to solve it?
From MSDN:
https://msdn.microsoft.com/en-us/library/ba1z7822.aspx?f=255&MSPPError=-2147217396
To add .lib files as linker input in the development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.
You must do this; explicitly specifying "libpng.lib", "zlib.lib" and "libpngd.lib" in your .exe's link command.
So this is coming from a complete simple minded moron so maybe this'll be helpful....it took me a little while to grasp. Basically, you're downloading the source code. That means, that you have to be the one to compile the source code.
Windows can compile programs that are written in C in the command prompt. You have to build the program, and it spits out a .dll or a .lib file. That or those are the files that you link to visual studio application.
You set dependencies to the header files which is usually like the source codes root folder or wherever all those .h files are.
You then set the linker to link to the .dll or .lib file(s). In Boost C++'s case, you need to link to a 'lib' folder.
I think what you need is to go over and completely grasp the basics. Here's a link from Microsoft on how Windows can compile C programs from the command prompt:
https://learn.microsoft.com/en-us/cpp/build/walkthrough-compile-a-c-program-on-the-command-line?view=vs-2019

Linking a DLLs in visual studio 2013

I've already looked for solution, without a success.
I need to use a DLL supplied by third parties on Visual Studio 2013(running on (x64) Windows 10).
On machine there are both OpenCV 3.0.0 and OpenCV2.410 installed and working.
The DLL's author has provided a .lib file and He says that in order to use this DLLs in your project, you need to put some others OpenCV's dlls in the project folder( I've tried to put these DLLs in every project folder[yes I know, it has no sense, but after a lot of tries i've lost my patience])
What he supplies is an .dll and an example project( that doesn't work for me because it needs OpenCV2.1 and there are instructions needs to be translate in newest version [and I prefered don't translate nothing]).
The errors in this example project are of this kind:
error LNK2001: unresolved external symbol
fatal error LNK1120: unresolved externals
The most of them are caused by the miss of OpenCV2.1, that I don't want to install, because I'll have to use it on a program using with OpenCV 3.0.0.
In the example project folder there are:
The upper mentioned .dll
A .lib file
The header file .h
These DLLs: cv210.dll, cxcore210.dll, highgui210.dll, ...(eg. cv210d.dll)
What I've done is this:
A folder called "lib" where I insert all .dll, .lib, .h files.
Put the "lib" folder in Project properties>linker> General> Additional Library Directories
Writing the .lib file in properties>linker> Input> Additional Dependencies
Put the 'lib' pathproperties>C/C++>Additional Include Directories[I know, this has no sense too]
I get these kind of errors:
error LNK2001: unresolved external symbol
I've tried #pragma comment(lib, 'file.lib') way too.
Someone can help me?

How to use the OpenCV 2.4 static libraries with Visual Studio?

I'm trying to set up OpenCV 2.4 as follows:
I've downloaded and extracted the precompiled package to C:\OpenCV240.
In Visual Studio, I've added C:\OpenCV240\build\include as an additional include directory.
Furthermore, I've added C:\OpenCV240\build\x86\vc10\staticlib as an additional library directory.
And I've specified all available .lib files as additional dependencies.
When I compile my "Hello World" program (which compiles just fine when using the DLLs), I get a lot error messages like this:
1>msvcprtd.lib(MSVCP100D.dll) : error LNK2005: "public: __thiscall std::_Container_base12::~_Container_base12(void)" (??1_Container_base12#std##QAE#XZ) already defined in opencv_core240d.lib(matrix.obj)
What am I doing wrong?
It sounds like you need to specify linking against the static C runtime library in your program.
If OpenCV linked against the static CRT and you use the dynamic one, you get these types of redefinition errors.
To change this setting, open your project's Properties and go to Configuration Properties -> C/C++ -> Code Generation.
Change Runtime Library from Multi-threaded Debug DLL (/MDd) to Multi-threaded Debug (/MTd). Do the same for your other configurations, using the non-Debug variant where appropriate.

ImageMagick static compilation with another project gives linker errors

I've downloaded the ImageMagick source, compiled the wizard to create a Visual Studio solution for static linkage, and included the static library Magick++ project in my sample project (code below). I've also added a dependency on that project and included the .lib file in the solution, nothing helps.
#include <Magick++.h>
int main()
{
Magick::Image image;
bool test = image.isValid();
return 0;
}
This gives several linker errors, such as:
unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Magick::Image::~Image(void)" (__imp_??1Image#Magick##UAE#XZ) referenced in function _main
Why can't it find the implementation?
I'm using Visual Studio 2010 Beta 2.
The problem may rise from that you are using different compiler than the library was compiled with. As your compiler is fairly new, it's very likely it uses different name mangling and can't find method signatures inside the library.
The answer to linking the ImageMagick static libraries is to ensure you link ALL the dependant static libraries as well!
Once you have compiled the solution for ImageMagick static libraries, go to the 'VisualMagick' folder (within the ImageMagick cloned repository) then to to the 'lib' folder there you will see all the _DB_.lib and _RL_.lib files for Debug and Release.
You need to include those names in the 'Additional Dependencies' section for both Release and Debug.
You must also ensure you have the Library folder path in the 'Additional Library Directories' for both Release and Debug.
Another key aspect is to ensure the libraries are built by the same compiler for the same platform architecture as your own application .. (WIN32 or x64).
This error is strange - The compiler is looking for a function from a DLL (__declspec(dllimport)). Are you sure you are using the right header files ?