views:

52

answers:

1

Hi,

I've tried searching A LOT for this with no luck (possibly because I'm not using the right technical terms). My issue is mainly to do with linking static libs, compiling and deploying. Before I get into details, my executables compile fine on my system; the main issue is how to deploy these as a working solution to others.

I've written a basic c++ image processing exe that uses OpenCV static libraries (I link these in VC++ using the Project>Properties>Linker> add additional dependencies, as standard). I compile by pointing to the right include files by setting the VC++ Options... basically, it all compiles fine. I now want to be able to deploy this on another PC. I understand I'll need the release version of the exe + static libs... is there anything else?

Some of the libs rely on using libjpeg and libpng; I don't think these are included as standard. Also, I've set the linker path to the static libs to be relative (e.g. resources/libs) so it's not system dependent so it knows where to find the libs. The basic OpenCV data strucs are working fine (e.g. CvPoint), but when I try to load an image using CvLoadImage, the application crashes. If I use standard ifstream fopen instead, I can open the file with no problems (but can't seem to get it into the IplImage OpenCV image strut - does anyone know how to do these? Probably to do with IplImage->imageData.).

Any help very much appreciated. Thanks!

+1  A: 

Static libraries do not have to (and should not) be distributed with the application. Static libraries are built into the exe file by the linker.

The reason why OpenCV crashes is that it cannot find libpng/libjpeg dlls. OpenCV doesn't link them as static dependencies but uses LoadLibrary/dlopen APIs at runtime instead. If these calls fail, there's probably no nice recovery and the application crashes. Your problems should be fixed if you include the libpng/libjpeg libraries.

Also beware - some .lib files aren't truly static libraries but are just a thin layer that allows the linker to find the appropriate functions in a DLL and generate the dynamic linking code so that the programmer doesn't have to do that by hand. You will usually see that from the .lib file size that is pretty small and that your application cries that it cannot find a DLL entry point at the startup of the exe..

dark_charlie
Thanks dark_charlie, I had suspected that this was the issue as other functions were working ok. I can only find libjpeg.lib and libpng.lib. Do I add these along with the other libs or should there be DLLs that I upload seperately? If so, how should I reference them in VC++? Thanks once again.
daz
You should put the dlls, libs are never distributed with the application. You do not have to change anything in VC++, simply copy the DLLs to the folder where the exe resides.
dark_charlie
Ok so from reading around this is what I gather:1. I have to add the libjpeg.lib and libpng.lib in the Project Properties>Linker>Input>Additional dependencies2. Include libjpeg.h and libpng.h in the main CPP code.3. Copy libjpeg.dll and libpng.dll into the release exe directory.I've tried all of those with no luck.
daz
Have you compiled OpenCV yourself or have you used the precompiled binaries? If yourself, what line does the program crash on when you run it in debugger?
dark_charlie
Hi, thanks, I've managed to get somewhere after messing around with it for ages. I don't know what exactly did it but it was tedious! Thanks once again for your advice.
daz