amersons / leptonica

Automatically exported from code.google.com/p/leptonica
0 stars 0 forks source link

/prog programs can't link with Windows DLL version of leptonica. #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try to build a DLL version of leptonica and then have ioformats_reg link
to the DLL.

What is the expected output? What do you see instead?
I expect to be able to link ioformats_reg with the DLL version of leptonica.
Instead I see:
error LNK2001: unresolved external symbol _ImageFileFormatExtensions
ioformats_reg.obj   ioformats_reg

What version of the product are you using? On what operating system?
leptonlib-1.64
Microsoft Visual Studio 2008 SP1 with latest updates also applied.
Windows XP Pro SP3.

Please provide any additional information below.
This turns out to be an insidious problem that's probably strewn throughout
leptonica.

To fix this SPECIFIC problem I had to change writefile.c from:

  l_int32  NumImageFileFormatExtensions = 16;  /* array size */
  const char *ImageFileFormatExtensions[] = {"unknown",

to:

  LEPT_DLL l_int32  NumImageFileFormatExtensions = 16;  /* array size */
  LEPT_DLL const char *ImageFileFormatExtensions[] = {"unknown",

in order to tell the MSVC compiler to export those two data items to the DLL.

Additionally, ioformats_reg.c had to be changed from:

  extern const char *ImageFileFormatExtensions[];

to:

  LEPT_DLL extern const char *ImageFileFormatExtensions[];

I also had to change the project settings for ioformats_reg so that
LEPTONLIB_IMPORTS is defined, then the following is done:

  #define LEPT_DLL __declspec(dllimport)

But that seems a bit confusing to me since the same LEPT_DLL is used for
both specifying DLL exports and imports (depending on whether you are
building leptonica or a program that links with leptonica).

In any case, any data that is supposed to be visible in leptonlib will have
to be prefaced with LEPT_DLL. Additionally, any extern data in the prog
programs will also have to be prefaced with LEPT_DLL.

Original issue reported on code.google.com by wing...@gmail.com on 16 Feb 2010 at 7:29

GoogleCodeExporter commented 9 years ago
I believe the few globals in the library have been prefaced.

And the prog files were all checked for extern use of these variables,
and prefaced there as well.  So this seems to be fixed.

Original comment by dan.bloo...@gmail.com on 8 Apr 2010 at 6:12