强制 conda 安装的可执行文件在运行时使用 conda 共享库



我想使用conda使C++程序的编译和分发变得可移植和简单,所以我写了一个 conda 配方。构建依赖于一些库来处理映像 I/O,例如libpnglibtiff。这些库的conda版本在配方中指定,摘录如下所示:

requirements:
run_exports:
strong:
- libpng
- libtiff
- jpeg
- fftw
- eigen
host:
- {{ compiler('cxx') }}
- cmake
- python
- libpng
- libtiff
- jpeg
- fftw
- eigen
run:
- libtiff
- libpng
- jpeg
- fftw

我的理解是,host对应于编译期间使用的 Conda 库,而runrun_exports在主机或其他机器的运行时指定库。

在 OS X 上,cmake 编译运行正常,特别是针对图像库的 conda 版本成功编译。在conda build .操作中发生的安装摘录如下所示:

-- 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

在 conda 构建过程结束时,我将包上传到anaconda存储,并安装它 (conda install -c efmkoene bm3d)。但是经过测试,事实证明可执行文件正在为映像I/O使用一组不同的库 - 在我的情况下造成了麻烦。针对图像运行的程序示例(例如,bm3d ~/Downloads/example.png 10 out.png)给出了

libpng warning: Application built with libpng-1.4.12 but running with 1.6.37
ERROR(""): png_create_read_struct fail

请注意,运行时的libpng(在本例中为brew install libpng的结果)与用于编译的不同,即使我与用于编译的运行时环境处于同一运行时环境中。有解决此问题的方法吗?

为了将来参考,错误确实是在cmake过程中检测到有关libpng的错误信息。在CMakeLists.txt中添加set(CMAKE_FIND_FRAMEWORK LAST)解决了这个问题!正如 Kikaxa 在 OSX + 自制软件 + CMake + libpng 版本不匹配问题中报告的那样:

问题是经典的 cmake 样式 Find*.cmake 搜索 标头和库分别 - 结果可能和将 在某些情况下不匹配。MacOS通过 框架的特殊情况,在其他位置之前被搜索 违约。

最新更新