I need a image library and I've been looking into FreeImage, http://freeimage.sourceforge.net/. I want to link it statically with my application.
I have tried downloading the binaries and link it with, but I get 2019 linker errors when I try to call their functions, even though I am positive I linked it correct.
So then I tried to download their source, converted their "FreeImageLib.2008" to VS2010 and built it. It builds just fine on its own, but I still have the same problem when linking against it, my application that uses it still complaints about linker errors.
I also set all the project configuration to match my other projects, so there is no conflict with /MDd or /MTd, etc..
I did some digging in their source and there are macros like "FREEIMAGE_LIB" which suggests it should be defined when building a static library, and it IS defined, yet still it dosn't work.
I've googled around and cannot find any solid answers to this issue. The answer on Getting FreeImage to work with Visual Studio 2010 makes no difference; I already defined the macro either before including the header or as a preprocessor argument but it dosnt work.
Is this library not meant to be used as a static library, or what could possibly be the issue? Has anyone been able to link FreeImage statically on VS2010+?
Thanks
Yes, I've been able to link FreeImage statically on several Visual studio versions. Here I describe how I do this usually.
With FreeImage, by default, we have 8 options to link it to your app:
FreeImage - dynamic link (you will need dll).
FreeImageLib - static link.
Each of these can be built with "Debug" or with "Release" configurations and for Win32 or Win64 platforms.
So, assume that we need ( Static && Win32 && Debug ) and ( Static && Win32 && Release ) variants for our app. Also in our app we use Dynamic Runtime Library (by default, FreeImage set up for static for some reason) How we usually got it:
Download and unpack fresh version (or at least clean up old distib)
Open FreeImage.2008.sln
select ALL of 10 projects with Shift+click. Then in "Project(s) Properties / C++ / Code generation" we choose /MDd for "Debug" configuration and /MD for "Release".
Then we go to "Menu / Build / Batch build", select:
FreeImageLib | Debug | Win32
FreeImageLib | Release | Win32
and press "Build".
Wait for choosen configurations built. All what we need will be copied in FreeImage\Dist
folder
in FreeImage\Dist
folder check files:
delete.me
FreeImage.h
FreeImage.lib
FreeImaged.lib
Check creation date and time. It must be fresh baked and hot. If they not, copy them from FreeImage\Source\FreeImageLib\Debug
and FreeImage\Source\FreeImageLib\Release
.
FreeImage\Dist
and link FreeImaged.lib
to Debug configurations and FreeImage.lib
to Releases.Include in source file:
#define FREEIMAGE_LIB
#include "FreeImage.h"
Try to call
FreeImage_Initialise();
FreeImage_DeInitialise();
It should work
Happy coding!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With