I want to make the compilation and distribution of a C++ program portable and simple using conda
, so I've written a conda recipe. The build depends on some libraries to deal with image I/O, for example libpng
and libtiff
. The conda
versions of these libraries are specified in the recipe, an excerpt is shown below:
requirements:
run_exports:
strong:
- libpng
- libtiff
- jpeg
- fftw
- eigen
host:
- {{ compiler('cxx') }}
- cmake
- python
- libpng
- libtiff
- jpeg
- fftw
- eigen
run:
- libtiff
- libpng
- jpeg
- fftw
my understanding is that host
corresponds to the conda libraries used during compilation, while run
and run_exports
specify the libraries during runtime at the machine of the host or other machines.
On OS X, the cmake compilation runs normally, and in particular successfully compiles against the conda versions of the image libraries. An excerpt of the installation as takes place within the conda build .
operation is shown below:
-- The C compiler identification is Clang 12.0.1
-- The CXX compiler identification is Clang 12.0.1
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: $PREFIX/bin/x86_64-apple-darwin13.4.0-clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: $PREFIX/bin/x86_64-apple-darwin13.4.0-clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenMP_C: -fopenmp=libomp (found version "5.0")
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.0")
-- Found OpenMP: TRUE (found version "5.0")
-- Found TIFF: $PREFIX/lib/libtiff.dylib (found version "4.0.9")
-- Found JPEG: $PREFIX/lib/libjpeg.dylib (found version "80")
-- Found ZLIB: $PREFIX/lib/libz.dylib (found version "1.2.11")
-- Found PNG: $PREFIX/lib/libpng.dylib (found version "1.4.12")
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
CMAKE_INSTALL_LIBDIR
CMAKE_LIBTOOL
-- Build files have been written to: $SRC_DIR/build
Scanning dependencies of target bm3d
[ 16%] Building CXX object CMakeFiles/bm3d.dir/bm3d.cpp.o
[ 33%] Building C object CMakeFiles/bm3d.dir/iio.c.o
[ 50%] Building CXX object CMakeFiles/bm3d.dir/lib_transforms.cpp.o
[ 66%] Building CXX object CMakeFiles/bm3d.dir/main.cpp.o
[ 83%] Building CXX object CMakeFiles/bm3d.dir/utilities.cpp.o
[100%] Linking CXX executable bm3d
[100%] Built target bm3d
Consolidate compiler generated dependencies of target bm3d
[100%] Built target bm3d
Install the project...
-- Install configuration: "Release"
-- Installing: $PREFIX/bin/bm3d
At the end of the conda building process, I then upload the package to the anaconda
store, and install it (conda install -c efmkoene bm3d
). But then upon testing, it turns out the executable is using a different set of libraries for the image I/O -- in my case causing trouble. An example of the program run against an image (e.g., bm3d ~/Downloads/example.png 10 out.png
) gives
libpng warning: Application built with libpng-1.4.12 but running with 1.6.37
ERROR(""): png_create_read_struct fail
Note thus how the libpng
on runtime (in this case, a result of brew install libpng
) is not the same as the one used for the compilation, even though I am in the same runtime environment as the one used for the compilation. Is there a fix for this problem?
For future reference, the error was indeed in the cmake
process detecting wrong info regarding libpng
. Adding set(CMAKE_FIND_FRAMEWORK LAST)
in the CMakeLists.txt
fixed the issue! As reported at OSX + homebrew + CMake + libpng version mismatch issue by Kikaxa:
The problem is that classical cmake-style Find*.cmake search for the headers and libraries separately - and the results MAY and WILL mismatch in some cases. MacOS exaggerates the problem by having special case of frameworks, being searched BEFORE other locations by default.