2

I was advised by some of you not to long ago to use FreeImage as a library for image processing in C++.

I now have some trouble in getting the library to work (still relatively new here).

I've tried loading the various vcxproj and sln tiles and they gave me a blank project. Since there isn't any installation instructions provided for that, I gave up on making it a visual studio solution.

I next tried the old-fashion way of compiling the source code using the Makefile and then adding "FreeImage/Source" to the linker. While the IDE does not raise any red flags when I call functions declared in FreeImage.h, it gave me a bunch of "error LNK2019: unresolved external symbol" during compilation, as if the functions do not exist. What I suspect is that the IDE could not find the .cpp files that define the said functions, but I still get that same problem when I added FreeImage/Source/FreeImage to the linker.

Now when I directly included some of the .cpp files (i.e. Plugin.cpp and FreeImage.cpp) for a test, I get even more unresolved external symbol errors as well as things like "inconsistent dll linkage" for this within... for example FreeImage.cpp:

const char * DLL_CALLCONV FreeImage_GetVersion() { static char s_version[16]; sprintf(s_version, "%d.%d.%d", FREEIMAGE_MAJOR_VERSION, FREEIMAGE_MINOR_VERSION, FREEIMAGE_RELEASE_SERIAL); return s_version; }

So, I am totally stuck. What am I doing wrong? I felt I've followed the adequate steps in adding library dependencies, such as adding the specific folders that are immediate parents to the relevant .h and .cpp files in C/C++ -> General -> Additional Included Directories and Linker -> General -> Addition Library Directories.

Some help will be greatly appreciated!

Community
  • 1
  • 1
Some Newbie
  • 1,059
  • 3
  • 14
  • 33
  • "I've tried loading the various vcxproj and sln tiles and they gave me a blank project." Could you clarify that? What exactly did VC2010 say? – Nicol Bolas Feb 10 '12 at 10:03
  • VC2010 would do the conversion process and then when it's done, I see a solution with a bunch of projects (i.e. FreeImage, LibPng, etc) where each project is empty - No headers, no source, zilch. However, do you have any suggestions for me on trying to simply include the library folders? As I've described, VC is giving me issues on that too. – Some Newbie Feb 10 '12 at 20:34
  • The problem seems to be associated with DLL's (I am a new C++ user - are they like .jar files?). The error LNK2019 messages actually are "unresolved external symbol __imp__[insert function name] errors and Google told me that __imp__ implies functions are imported from a .dll (some C++ version of .jar file?). Digging through FreeImage.h, I do see some lines like `#ifdef FREEIMAGE_EXPORTS #define DLL_API __declspec(dllexport) ` and the fxns that had LNK error look like `DLL_API FIBITMAP *DLL_CALLCONV fxn()` I am not sure how these vars are assigned values. – Some Newbie Feb 11 '12 at 00:35
  • I'm experimenting the same issue. – Salvatore Dario Minonne May 13 '12 at 08:00

1 Answers1

3

Using FreeImage v3.15.3 I had no problems converting the VS2008 project to VS2010. Also the building worked as expected. But when I linked to the static lib, I got some unresolved externals. First I tried al kinds of tricks setting /MT /MD linking, but that did not solve these linking problem.

After reading Some Newbie's comment I dug into freeimage.h. There I found a macro switch FREEIMAGE_LIB that controls the calling conventions of the function. Use a #define FREEIMAGE_LIB before including the freeimage.h file. That way you can easily static link to FreeImage.lib

Tom
  • 31
  • 2