ImageMagick static compilation with another project gives linker errors - c++

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 ?

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.

Problems linking Nlopt-2.4.2 in visual studio 2017

Some back story: I am trying to get the bolt-lmm software to compile on a Windows machine, because it would be a nice addition to the research group I am in. The developers of the software have only made a linux static executeable, but made the source code available. I am used to programming in R or python, and this is my first ever encounter with C++.
I have solved a fair bit of problems, but for some reason I have not been able to get visual studio to link properly with Nlopt-2.4.2.
I downloaded it
and followed the steps given there on how to install it.
I can tell I have done the same to link the Nlopt library to the project as is described in How to add additional libraries to Visual Studio project?
I still get errors like:
Error LNK2019 unresolved external symbol __imp__nlopt_create referenced in function "public: __thiscall nlopt::opt::opt(enum nlopt::algorithm,unsigned int)" (??0opt#nlopt##QAE#W4algorithm#1#I#Z) boltCompiler C:\Users\au483192\source\repos\boltCompiled\boltCompiler\NonlinearOptMulti.obj 1
(there are a total of 12 of this type of error, and an error link 1120, which just tells me there are 12 unresolved eternals.)
I hope this is enough information to provide a hint of what is going wrong.
I did some more digging, and it seems the linker needed more than just the folder for the .lib file.
This post sums it up:
Linking a static library to my project on Visual Studio 2010
Essentially you just need to tell the linker the placement of the lib and the actual name of the .lib file.
Hopefully this will help others who forgot/did not know that added library names manually could be needed for some libraries.
TL;DR:
open configuration properties for the project > linker > general
Then add the path to the .lib file in the "addition library directories" line
Then (still in configuration properties) go to linker > input
add the .lib file name to the "addition dependencies" line, e.g. libnlopt-0.lib (don't forget to separate with ";")

Intel IPP: unresolved external symbol _ippiResizeGetSize_8u#32

I am having an odd issue and think there is a simple answer to that but I guess I just can't see the forest because of all the trees.
I am trying to compile a program using Intel IPP (Visual Studio 2015) and get the following error message:
unresolved external symbol _ippiResizeGetSize_8u#32
I added the appropriate folders to the project properties, which did not work. So just to be on the safe side I just copied all static libs and the corresponding header files into the folder where to code of the program lies. It does find the header files but I am also getting the above error. The libs are added as dependencies. I have set IPP so that it uses single-threaded static libraries.
What am I doing wrong here? It seems to be straightforward.
Thank you
Pat
All unresolved symbol error come from VS linker. Basically, it means that you haven't added to linker "input" property the static library, which resolves the required external name.
In your case it is IPP image processing library, i.e. "ippimt.lib" (of the latest IPP versions), or "ippi_l.lib" of IPP v.7.x.
You can add the full name of ippi* library to "input" property, or add IPP library directory to the "general/additional directory" property of VS linker and name of the library file to "input" property. You don't need to copy static libraries to working directory, it doesn't work.
Regards, Sergey

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.

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.