Linking FreeImage as a static library in VS2010?

I need an image library, and I looked at FreeImage, http://freeimage.sourceforge.net/ . I want to link it statically with my application.

I tried loading the binaries and linking them, but I get 2019 linker errors when I try to call their functions, although I am sure that I bound it correctly.

So, I tried to download their source, converted them to "FreeImageLib.2008" in VS2010, and built it. It just works great on its own, but I still have the same problem when you contact it, my application that uses it still complains about linker errors.

I also set the entire project configuration to match my other projects, so there is no conflict with / MDd or / MTd, etc.

I did some digging at their source, and there are macros such as "FREEIMAGE_LIB", which suggests that it must be defined when creating the static library, and it is defined, but still it does not work.

I googled around and can't find any solid answers to this problem. The answer to Getting FreeImage to work with Visual Studio 2010 does not matter; I already defined the macro either before the header was included, or as an argument to the preprocessor, but dosnt works.

Is this library not intended to be used as a static library, or what could be the problem? Could anyone link FreeImage statically on VS2010 +?

thanks

+8
c ++ image freeimage
source share
1 answer

Yes, I managed to link FreeImage statically on several versions of Visual Studio. Here I describe how I usually do it.

With FreeImage by default, we have 8 options to associate it with your application:

FreeImage - dynamic link (you will need a dll).

FreeImageLib is a static link.

Each of them can be built using "Debug" or with "Release" configurations for both Win32 or Win64 platforms.

So, suppose we need (Static & Win32 & & Debug) and (Static & Win32 && Release) options for our application. Also in our application we use the Dynamic Runtime Library (by default, FreeImage is configured for statics for some reason) As we usually understand:

  • Download and unzip the new version (or at least clean the old file)

  • Open FreeImage.2008.sln select ALL 10 projects with Shift + click. Then in "Project (s) Properties / C ++ / Code generation" we select / MDd for the "Debug" configuration and / MD for the "Release".

  • Then go to the "Menu / build / build folders" section, select:

    FreeImageLib | Debug | Win32

    FreeImageLib | Release | Win32

and click Build.

  • Wait until the selected configurations are selected. All we need will be copied to the FreeImage\Dist folder

  • in the FreeImage\Dist folder verification files: delete.me FreeImage.h FreeImage.lib FreeImaged.lib Check the creation date and time. It should be freshly baked and hot. If they are not, copy them from FreeImage\Source\FreeImageLib\Debug and FreeImage\Source\FreeImageLib\Release .

  • In the main application, add include and lib FreeImage\Dist and the FreeImaged.lib link in the Debug and FreeImage.lib for releases.
  • Include in source file:

    #define FREEIMAGE_LIB

    #include "FreeImage.h"

  • Try calling FreeImage_Initialise(); FreeImage_DeInitialise();

  • He should work

Happy coding!

+11
source share

All Articles