Magick++ with Borland Turbo C++ Builder

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
spankster01

Magick++ with Borland Turbo C++ Builder

Post by spankster01 »

I'm trying to compile a simple program (as a test to try and get things to compile) using the free Borland Turbo C++ compiler (basically a free version of Builder).

Here's my program:

Code: Select all

#include <iostream.h>
#include <Magick++.h>

int main(int argc, char* argv[])
{
	Magick::InitializeMagick(*argv);
	Magick::Image image;
	return 0;
}
Pretty simple, I know. The problem is that I get a linker error and can't even compile this simple program. I've installed the windows ImageMagick-6.4.7-8-Q16-windows-dll.exe binary package and have added the /include directory to the include search path of the compiler, and the /lib directory to the linker include path. I get an error:

[Linker Error] Error: Unresolved external 'Magick::Image::~Image()' refereced from ...\testjpg.obj

where ...\ is the full path to my object file. I get this error three times, once for the Image() constructor, once for the destructor (as shown above) and once for Magick::InitializeMagick(const char *). The .cpp file above will compile but it will not build. It seems like it can't find the .lib files to link to, but I'm certain that I've added the /lib directory to the search path (and I've also tried copying them all into the working directory to no avail). Does anyone have any suggestions? Is anyone out there successfully using Magick++ with a Borland compiler?

Your help is greatly appreciated!
Thanks,
Mike
ptast

Re: Magick++ with Borland Turbo C++ Builder

Post by ptast »

Hi Mike,

I use Borland C++ Builder and the C API. I've never tried the Magick++ using borland but it should link.

Have you converted the lib to OMF, CORE_RL_Magick++_.lib ?

Code: Select all

coff2omf -lib:ms CORE_RL_Magick++_.lib CORE_RL_Magick++_bc.lib
You must also tell in your .mak file to link with CORE_RL_Magick++_bc.lib

Code: Select all

LIBFILES = ..\ImageMagick\lib\CORE_RL_Magick++_bc.lib
Hope that helps,
Patrik
spankster01

Re: Magick++ with Borland Turbo C++ Builder

Post by spankster01 »

Patrik,

Thanks for the reply, let me give you a quick update on my status. My original error I believe was caused by me not adding the .lib files to the project (which I believe essentially tells the linker to get them, like your suggestion for "LIBFILES=..."). So I added the .lib files to the project and then I got the error "contains invalid OMF record, type 0x21 (possibly COFF)." So I did some digging and apparently this error is because the .lib's follow the microsoft COFF naming convention. So I used the COFF2OMF conversion tool exactly like you described below. Then I removed the original .lib's from the project and added the new OMF'd .lib's.

So now I'm back to getting the same original error, [Linker Error] Error: Unresolved external 'Magick::Image::~Image()' refereced from ...\testjpg.obj

I assume that the COFF2OMF converter did not actually convert all of the function/object names. Could it be because the .lib/.dll I'm trying to use is a C++ file with objects instead of just simple C style functions? The new .lib file created by the conversion tool is much smaller than the original (414 KB instead of 1063 KB).

Anyone have any other ideas?
Thanks,
Mike
ptast

Re: Magick++ with Borland Turbo C++ Builder

Post by ptast »

Hi Mike,

Yeah, I got exactly the same result so I started investigating some.
I run impdef.exe on CORE_RL_Magick++_.dll

Code: Select all

impdef CORE_RL_MAGICK++_.def CORE_RL_MAGICK++_.dll

LIBRARY     CORE_RL_MAGICK++_.DLL

EXPORTS
    ??0?$_List_nod@VCoordinate@Magick@@V?$allocator@VCoordinate@Magick@@@std@@@std@@IAE@V?$allocator@VCoordinate@Magick@@@1@@Z @1   ; ??0?$_List_nod@VCoordinate@Magick@@V?$allocator@VCoordinate@Magick@@@std@@@std@@IAE@V?$allocator@VCoordinate@Magick@@@1@@Z

ETC
We can see that it is corrupt. If we again run impdef.exe on CORE_RL_magick_.dll

Code: Select all

impdef CORE_RL_MAGICK_.def CORE_RL_MAGICK_.dll

LIBRARY     CORE_RL_MAGICK_.DLL

EXPORTS
    AcquireCacheView               @1   ; AcquireCacheView
    AcquireCacheViewIndexes        @2   ; AcquireCacheViewIndexes
    AcquireCacheViewPixels         @3   ; AcquireCacheViewPixels
    AcquireDrawInfo                @4   ; AcquireDrawInfo

    ETC
We can see that it is OK. I now wonder if Magick++_.DLL is built using some other flags?

I tried also to import a library using impdef.exe but the linker crashed (Access violation),

Reason why Borland C++ linker behaves like this could be missing
extern declarations in Magic++ headers?

Code: Select all

#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif

....code....

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
If you do not have impdef.exe here is a version
http://www.poes-weather.com/~patrik/IM/bcc-utils.zip (215 kb)

Patrik
pif1709

Re: Magick++ with Borland Turbo C++ Builder

Post by pif1709 »

Any solutions for this problem?

Thx
spankster01

Re: Magick++ with Borland Turbo C++ Builder

Post by spankster01 »

pif1709 wrote:Any solutions for this problem?

Thx
I suspect that someone with more knowledge of the DLL building process, more experience with C++ in general, and more time, could have probably figured this out. But as I have none of those things, I was completely stumped. My solution was to use Microsoft Visual C++ Express, which is also a free compiler/tool and has a nice Forms builder as well that I found worked just as well as Borland.

And actually, I ended up moving to C# (also using the free Express tool) and MagicNet.dll which I found worked great and was super easy to get working in my project. Plus after working with it a bit I've found that I really like .NET.... Managed code is great and the libraries of functions provided in .NET are really good.

Mike
Post Reply