Recent

Author Topic: Empty image bitmaps with Freeimage library when statically linked...  (Read 8044 times)

mvaldez

  • New Member
  • *
  • Posts: 10
Hi. I'm migrating a Delphi application to Lazarus, and the original application uses FreeImage library (freeimage.sourceforge.net) for image processing. After some changes in my application, it worked, if the library is installed in the system (in this case, Ubuntu 10.04, 64-bits) as shared library, but if I try to statically link the FreeImage library (only this library), I can't load any image, all functions always return NIL and FreeImage_GetFileType always returns FIF_UNKNOWN.

This is what I did:

1. Modified my code (minor changes in my wrapper, specially to account for differences in Linux).

2. Installed the FreeImage library available from the Ubuntu repositories (libfreeimage3, which is FreeImage 3.10.0, as dynamic library, .so). Added missing link from /usr/lib/libfreeimage.so to /usr/lib/libfreeimage-3.10.0.so or the linker won't find it.

3. Tested my application. It worked.

4. Removed the Ubuntu FreeImage library.

5. Compiled the FreeImage library manually. Copied the libfreeimage.a ar file to my project directory. Added option "-L /myprojectdir" to linking options in Compiler Options dialog, so that the linker could find the static library.

6. When compiling I got lots of error messages about undefined references like "BitmapAccess.cpp:(.text+0x3eb): undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base*)'", so I added "{$linklib stdc++}" to my wrapper.

7. Compilation was successful, but now I can't load any image file. All calls to FreeImage_GetFileType return FIF_UNKNOWN, and all calls to FreeImage_Load return NIL. No crash, no warning, just silently fails to load the images.


First I thought it was a problem with my manually-compiled version of FreeImage. To test this, I installed the builded libfreeimage-3.13.1.so (the shared version) file (copied it to /usr/lib and ran ldconfig) and tried to compile my application again. It compiled, and it worked as expected.


So, with FreeImage as shared library it works, with FreeImage as static library it fails. Has anybody seen this before?


As a side note, for anybody wondering, I decided to link FreeImage statically because it is not a common library and I don't know if it will be available in all target systems (which is a different case for libgtk or most libX* libraries). Maybe this is the wrong approach and I may need to put more effort in preparing packages with good dependencies for the target, but for now I'll test this way.


Regards,

MV



mvaldez

  • New Member
  • *
  • Posts: 10
Re: Empty image bitmaps with Freeimage library when statically linked...
« Reply #1 on: July 27, 2010, 12:20:36 am »


Solved. Silly me. I have rechecked the FreeImage documentation and I found out I need to call FreeImage_Initialise before using the FreeImage library only if it is statically linked (and I have to call FreeImage_DeInitialise when finished). So I added those functions to my wrapper and now I'm calling them at the initialization and finalization parts of my code.

Now it works.

Sorry for the noise in these forums (and I hope this helps someone else in the future).


Regards,

MV

agorka

  • New Member
  • *
  • Posts: 25
Re: Empty image bitmaps with Freeimage library when statically linked...
« Reply #2 on: October 18, 2013, 10:57:04 am »
Sorry for upping such a historic thread, but I can't find an answer to my question anywhere else.

I'm trying to make application in both Delphi / Lazarus, and now it's in Windows.
Can you give me some info, how to link freelibrary into my program .EXE file?
Do I need some C compiler to build freelibrary?

Thanks!
Oleg.

 

TinyPortal © 2005-2018