What .h and .lib files to include/link against ?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
Minok
Posts: 21
Joined: 2014-04-24T15:51:58-07:00
Authentication code: 6789

What .h and .lib files to include/link against ?

Post by Minok »

Not being able to find a post on the internet following many searches and some time, I'm going to ask this basic question here.

I'm wanting to use ImageMagick as static libraries (.lib) that I will link to from my own c/c++ program - by using the C API. Pretty straight forward.

I downloaded the source, built and ran the configure program, and then built the whole caboodle based on that config run.

Now, from what I can tell, the static library files are all in ImageMagick-6.8.9\VisualMagick\lib
And the .h files are all elsewhere, in ImageMagick-6.8.9\magick

Now the problem, I only want to add the .lib and .h files to my own project, if that .h and .lib are actually needed.
So first I tried just MagickCore.h... and quickly found that it wants a host of things in a magick subdirectory, so I created a magick subdirectory in my source tree and copied all the .h files there.

Ok, compile works, but now which .lib files do I need to link against? There are 27 .lib files of the form CORE_DB_xxx_.lib in the VisualMagick/lib directory.
I started with just linking against Core_DB_magick_.lib, but that isn't enough, trying to just do the basics in my source:

(my Visual Studio solution includes in the project 2 files directly in a VS filter: CORE_DB_magick_.lib, and MagickCore.h, the other .h files are in the project directory but not explicitly listedn in the VS project )

Code: Select all

// For the ImageMagick Library
#include "MagickCore.h"
...
		Image* imgMagickImage;			// an imagemagick image handle
		ImageInfo* imgMagickInfo; // the imagemagick image info object
		ExceptionInfo* imgMagickException;	// where exception information is stored from calls

		MagickCoreGenesis(".", MagickTrue);	// initialize the imagemagick environment
results in a host of linker errors about unresolved external symbols from CORE_D B_magick_.lib referencing a variety of .obj files (eg static.obj, blob.obj, annotate.obj, ...)

Should I be linking against more of the .lib files? If yes, which ones? I don't want to put 27 items in the linker line in VisualStudio 2010, there has to be some way of knowing which .h and .lib files I need in order to use which of the C API functions.

I'm guessing that the magic sauce from the sample program source shown for using the core API, `pkg-config --cflags --libs MagickCore`, might answer that question, however as there is no pkg-config on my install I cannot run that magic sauce to find the answer to my question.

What I intend to do in my C/C++ program is decode a BLOB (CCITT, PNG or JPEG) into an image, possibly resize/process the image, and convert the image into a JPEG or PNG blob.
Minok
Posts: 21
Joined: 2014-04-24T15:51:58-07:00
Authentication code: 6789

Re: What .h and .lib files to include/link against ?

Post by Minok »

Here is the start of the stream of linker error messages...

Code: Select all

Error	273	error LNK2001: unresolved external symbol _cmsCloseProfile	C:\_Projects\<some path>\CORE_DB_magick_.lib(profile.obj)
Error	256	error LNK2019: unresolved external symbol _BZ2_bzclose referenced in function _CloseBlob	C:\_Projects\<some path>\CORE_DB_magick_.lib(blob.obj)
Its looking for symbols in a variety of the .obj files compiled into the CORE_DB_magick_lib.

At this point I have told visual studio to use MagickCore.h, it has compiler access to all of the .h files, and while only having a link dependency declared to CORE_DB_magick_.lib, the linker has access to the directory where all of the .lib files built for image magick are stored.

I'm going to rebuild ImageMagick VisualStaticMT.sln after it is recreated by the configure program, once more in case I made a mistake there:
-I included all of the UTIL parts this time
-I told it to use the full path names in the configure prog
-I'm using the UpgradeToVS2010.cmd file (rather than having VS2010 open the solution and upgrade internally)

Ok, I'm getting 'almost everything' to build - after running two build solution runs (first time through I got 20 something build fails, 2nd run just 1 so I assume that was just dependencies and VS oddity).

But the last build error is a compiler error that seems very odd, and appears to be a failure in building the project: UTIL_NtMagick:
Error 1 error C2039: 'InitializeMagick' : is not a member of 'MagickCore' C:\_Projects\<some path>\Libraries\ImageMagick-6.8.9\contrib\win32\MFC\NtMagick\NtMagick.cpp 76
TCHAR m_szAppPath[MAX_PATH];
(void) MagickCore::SetClientPath(m_szAppPath);
MagickCore::InitializeMagick(m_szAppPath);
MagickCore::RegisterStaticModules();

It complains that MagickCore has no member called "InitializeMagick". Ugh. Thoughts? I didn't futz with any of the solution before buidling.

Includes.h defines namespace MagickCore:
namespace MagickCore
{
#include <magick/MagickCore.h>
#include <wand/MagickWand.h>
#undef inline // Remove possible definition from config.h

#undef class
}
magick/MagickCore.h is a bunch of includes, and depends on
#if defined(MAGICKCORE_NAMESPACE_PREFIX)
# include "magick/methods.h"
#endif
#include "magick/magick-type.h"
#include "magick/accelerate.h"...

so with MAGICKCORE_NAMESPACE_PREFIX being defined by more macros, which depend on macros.. at this point I'm no longer able to clearly see what the compiler is actually trying to compile.


If I exclude UTIL_NtMagick from the build in configuration manager in Visual Studio and build the solution (build everything except UTIL_NtMagick), then I get all remaining 61 items to build.

Now I'm buidling releases of the lib, so they are of the form CORE_RL_magick_.lib, but still, I get a list of 293 errors related to unresolved symbols.

Knowing which additional .lib files contain the needed symbols is key I suspect, but how do I map the function names to one of the symbols?

Code: Select all

Error	270	error LNK2001: unresolved external symbol _cmsCloseProfile	C:\_Projects\<some path>\CORE_RL_magick_.lib(profile.obj)
Error	266	error LNK2019: unresolved external symbol _BZ2_bzclose referenced in function _CloseBlob	C:\_Projects\<some path>\CORE_RL_magick_.lib(blob.obj)
Error	253	error LNK2019: unresolved external symbol _BZ2_bzerror referenced in function _EOFBlob	C:\_Projects\<some path>\CORE_RL_magick_.lib(blob.obj)
Error	257	error LNK2019: unresolved external symbol _BZ2_bzflush referenced in function _SyncBlob	C:\_Projects\<some path>\CORE_RL_magick_.lib(blob.obj)
Error	260	error LNK2019: unresolved external symbol _BZ2_bzopen referenced in function _OpenBlob	C:\_Projects\<some path>\CORE_RL_magick_.lib(blob.obj)
Last edited by Minok on 2014-04-28T16:15:09-07:00, edited 1 time in total.
Minok
Posts: 21
Joined: 2014-04-24T15:51:58-07:00
Authentication code: 6789

Re: What .h and .lib files to include/link against ?

Post by Minok »

Well, putting all 27 static libraries in the Visual Studio "Additional Dependencies" field does get rid of the link issues (UGH!) Really? No way to do this without such a huge list of libraries, the bulk of which I'm not likely to even use?

Now I need to figure out the last few: one unresolved external symbol "_URLDownloadToFileA"
and a host of _f* already defined in LIBCMTD. (thats likley the debug vs release conflict).
Minok
Posts: 21
Joined: 2014-04-24T15:51:58-07:00
Authentication code: 6789

Re: What .h and .lib files to include/link against ?

Post by Minok »

Ok, some progress. Getting all of the code generation settings alinged to use MT, and not ignoring LIBCMT but ignoring MSVCRT to get rid of some (already declared in) linker problems has me down to ONE remaining linker error:

Error 1 error LNK2001: unresolved external symbol _URLDownloadToFileA@20 C:\_Projects\<project>\CORE_RL_coders_.lib(url.obj)

So what could be going on with that symbol? I'm linking against all of the .lib files the build-all produced. Where would URLDownLoadToFileA be defined?
Minok
Posts: 21
Joined: 2014-04-24T15:51:58-07:00
Authentication code: 6789

Re: What .h and .lib files to include/link against ?

Post by Minok »

Ok, I managed to get my library hell between this vast set of libraries, the other 3rd party libraries and my own application untangled. Whew. (Ignore the default MSVCRT, but not LIBCMT was the key).

So it appears I've worked my way through the problem. Hopefully this set of posts will serve to help future folks from having to rediscover this for themselves.

Still unresolved:
1) Util_NTMagick won't build in VisualStaticMT
Error 1 error C2039: 'InitializeMagick' : is not a member of 'MagickCore' C:\_Projects\<some path>\Libraries\ImageMagick-6.8.9\contrib\win32\MFC\NtMagick\NtMagick.cpp 76
2) The giant pile of lib files - could this not work in a better way with way less lib files?
Post Reply