3
votes

I'm using OpenCV in an iOS project but I'm having problems because the framework includes libpng and libjpeg, which my project also includes. This is causing duplicate symbols during link.

I'd like to point OpenCV at my own copies of libjpeg/png but I can't find any way to make that work. I tried setting the build variables BUILD_PNG and BUILD_JPEG to NO but that didn't have any effect and setting WITH_JPEG and WITH_PNG to NO caused the APIs to fail at runtime when I tried writing images due to the missing support.

I also considered just pointing my project at the OpenCV Framework's libjpeg/png headers but those aren't exposed through the framework. I could pull the source for the version in the framework and build against those headers so that the linkage would match, but yuck.

What is the right way to use OpenCV on iOS in a project which also uses libpng and libjpeg?

1

1 Answers

0
votes

I propose that you simply use OpenCV's versions of those libraries. That will require you to remove your own versions, and ensure you get copies of the correctly-versioned libpng and libjpeg headers.

I have just done this myself successfully for libpng - I need to get the headers for version 1.5.12. Note that for this version, you need the file pnglibconf.h which you can find in the libpng download as scripts/pnglibconf.h.prebuilt

My app was using libpng 1.2.34, and required very minor changes to work with 1.5.12.

I have also now done the same for libjpeg - I needed to get the headers for version 9 (libjpeg9). Again, you need a file jconfig.h, and the easiest way is simply to rename the bundled jconfig.txt.