libzip Linux交叉编译配置

libzip Linux交叉编译配置

我正在尝试交叉编译libzip-1.5.1之前已成功遵守zlib-1.2.11(这些是 libzip 所需的,并且我已安装在本地主路径中),但我在 cmake 进程中遇到了问题。

我用来构建和编译的脚本(从构建目录到 libzip 的源文件夹)如下:

#!/bin/sh

PREFIX=${PWD}/install
CCPATH=/opt/arm64/gcc-linaro-6.3.1-2017.02-rc2-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf
ZLIBPATH=${PWD}/../../zlib-1.2.11/

# here is where zlib is installed
# ZLIBINSTALLEDPATH contains include, lib, share directories
ZLIBINSTALLEDPATH=${ZLIBPATH}/build_armhf64/install/

export PKG_CONFIG_PATH="${PKG_CONFIG_PATH}:${ZLIBINSTALLEDPATH}/lib/pkgconfig/"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${ZLIBINSTALLEDPATH}/lib/"
export CMAKE_AR=${CCPATH}-ar
export CC=${CCPATH}-gcc
export CXX=${CCPATH}-g++
export CMAKE_LINKER=${CCPATH}-ld
export CMAKE_RANLIB=${CCPATH}-ranlib
export CMAKE_OBJDUMP=${CCPATH}-objdump
export CMAKE_OBJCOPY=${CCPATH}-objcopy
export CMAKE_STRIP=${CCPATH}-strip
#export CMAKE_READELF=${CCPREFIX}-readelf
export CMAKE_NM=${CCPATH}-nm

cmake -DCMAKE_INSTALL_PREFIX=${PREFIX} \
    -DZLIB_INCLUDE_DIR=${ZLIBINSTALLEDPATH}/include/  \
    -DZLIB_LIBRARY=${ZLIBINSTALLEDPATH}/lib/  \
     ../
make -j 8

但在构建过程的 94% 时,我收到以下错误:

[ 92%] Building C object regress/CMakeFiles/tryopen.dir/tryopen.c.o
[ 94%] Building C object src/CMakeFiles/zipcmp.dir/zipcmp.c.o
[ 94%] Linking C executable add_from_filep
[ 94%] Linking C executable fopen_unchanged
[ 94%] Linking C executable tryopen
[ 94%] Building C object regress/CMakeFiles/hole.dir/source_hole.c.o
[ 94%] Linking C executable zipmerge
../lib/libzip.so.5.0: undefined reference to `inflate'
../lib/libzip.so.5.0: undefined reference to `crc32'
../lib/libzip.so.5.0: undefined reference to `zError'
../lib/libzip.so.5.0: undefined reference to `deflate'
../lib/libzip.so.5.0: undefined reference to `deflateInit2_'
../lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `inflateInit2_'
collect2: error: ld returned 1 exit status
regress/CMakeFiles/add_from_filep.dir/build.make:95: recipe for target 'regress/add_from_filep' failed
make[2]: *** [regress/add_from_filep] Error 1
CMakeFiles/Makefile2:726: recipe for target 'regress/CMakeFiles/add_from_filep.dir/all' failed
make[1]: *** [regress/CMakeFiles/add_from_filep.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
../lib/libzip.so.5.0: undefined reference to `inflate'
../lib/libzip.so.5.0: undefined reference to `crc32'
../lib/libzip.so.5.0: undefined reference to `zError'
../lib/libzip.so.5.0: undefined reference to `deflate'
../lib/libzip.so.5.0: undefined reference to `deflateInit2_'
../lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `inflateInit2_'
collect2: error: ld returned 1 exit status
regress/CMakeFiles/tryopen.dir/build.make:95: recipe for target 'regress/tryopen' failed
make[2]: *** [regress/tryopen] Error 1
CMakeFiles/Makefile2:800: recipe for target 'regress/CMakeFiles/tryopen.dir/all' failed
make[1]: *** [regress/CMakeFiles/tryopen.dir/all] Error 2
../lib/libzip.so.5.0: undefined reference to `inflate'
../lib/libzip.so.5.0: undefined reference to `crc32'
../lib/libzip.so.5.0: undefined reference to `zError'
../lib/libzip.so.5.0: undefined reference to `deflate'
../lib/libzip.so.5.0: undefined reference to `deflateInit2_'
../lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `inflateInit2_'
collect2: error: ld returned 1 exit status
regress/CMakeFiles/fopen_unchanged.dir/build.make:95: recipe for target 'regress/fopen_unchanged' failed
make[2]: *** [regress/fopen_unchanged] Error 1
CMakeFiles/Makefile2:615: recipe for target 'regress/CMakeFiles/fopen_unchanged.dir/all' failed
make[1]: *** [regress/CMakeFiles/fopen_unchanged.dir/all] Error 2
[ 94%] Building C object regress/CMakeFiles/ziptool_regress.dir/source_hole.c.o
../lib/libzip.so.5.0: undefined reference to `inflate'
../lib/libzip.so.5.0: undefined reference to `crc32'
../lib/libzip.so.5.0: undefined reference to `zError'
../lib/libzip.so.5.0: undefined reference to `deflate'
../lib/libzip.so.5.0: undefined reference to `deflateInit2_'
../lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `inflateInit2_'
collect2: error: ld returned 1 exit status
src/CMakeFiles/zipmerge.dir/build.make:95: recipe for target 'src/zipmerge' failed
make[2]: *** [src/zipmerge] Error 1
CMakeFiles/Makefile2:432: recipe for target 'src/CMakeFiles/zipmerge.dir/all' failed
make[1]: *** [src/CMakeFiles/zipmerge.dir/all] Error 2
[ 94%] Linking C executable zipcmp
[ 94%] Linking C executable ziptool
[ 96%] Linking C executable hole
CMakeFiles/zipcmp.dir/zipcmp.c.o.:. /Inlib /functionlibzip.so.5.0 :` compute_crcundefined' :reference
 zipcmp.cto: (`.inflatetext'+
0x4a0.).:/ libundefined/ libzip.so.5.0reference:  toundefined  `referencecrc32 'to
 zipcmp.c`:crc32('.
text.+.0x53e/)lib:/ libzip.so.5.0undefined:  referenceundefined  toreference  `tocrc32 '`
zErrorCMakeFiles'/
zipcmp.dir./.zipcmp.c.o/:lib /Inlibzip.so.5.0 :function  undefined` test_filereference':
 zipcmp.cto: (`.deflatetext'+
0x1494.).:/ libundefined/ libzip.so.5.0reference:  toundefined  `referencecrc32'
zipcmp.c:(.text+0x14fe): undefined reference to `crc32'
.. /tolib /`libzip.so.5.0deflateInit2_:' 
undefined. .reference/ libto/ libzip.so.5.0`:inflate 'undefined
 .reference. /tolib /`libzip.so.5.0inflateEnd:' 
undefined. .reference/ libto/ libzip.so.5.0`:zError 'undefined
 .reference. /tolib /`libzip.so.5.0deflateEnd:' undefined reference to `deflate'
.
../.lib//liblibzip.so.5.0/:libzip.so.5.0 :undefined  undefinedreference  referenceto  to` deflateInit2_`'inflateInit2_
'.
./lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `collect2: error: ld returned 1 exit status
inflateInit2_'
collect2: error: ld returned 1 exit status
src/CMakeFiles/ziptool.dir/build.make:95: recipe for target 'src/ziptool' failed
make[2]: *** [src/ziptool] Error 1
src/CMakeFiles/zipcmp.dir/build.make:95: recipe for target 'src/zipcmp' failed
make[2]: *** [src/zipcmp] Error 1
CMakeFiles/Makefile2:469: recipe for target 'src/CMakeFiles/ziptool.dir/all' failed
make[1]: *** [src/CMakeFiles/ziptool.dir/all] Error 2
CMakeFiles/Makefile2:395: recipe for target 'src/CMakeFiles/zipcmp.dir/all' failed
make[1]: *** [src/CMakeFiles/zipcmp.dir/all] Error 2
../lib/libzip.so.5.0: undefined reference to `inflate'
../lib/libzip.so.5.0: undefined reference to `crc32'
../lib/libzip.so.5.0: undefined reference to `zError'
../lib/libzip.so.5.0: undefined reference to `deflate'
../lib/libzip.so.5.0: undefined reference to `deflateInit2_'
../lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `inflateInit2_'
collect2: error: ld returned 1 exit status
[ 98%] Linking C executable ziptool_regress
regress/CMakeFiles/hole.dir/build.make:121: recipe for target 'regress/hole' failed
make[2]: *** [regress/hole] Error 1
CMakeFiles/Makefile2:652: recipe for target 'regress/CMakeFiles/hole.dir/all' failed
make[1]: *** [regress/CMakeFiles/hole.dir/all] Error 2
../lib/libzip.so.5.0: undefined reference to `inflate'
../lib/libzip.so.5.0: undefined reference to `crc32'
../lib/libzip.so.5.0: undefined reference to `zError'
../lib/libzip.so.5.0: undefined reference to `deflate'
../lib/libzip.so.5.0: undefined reference to `deflateInit2_'
../lib/libzip.so.5.0: undefined reference to `inflateEnd'
../lib/libzip.so.5.0: undefined reference to `deflateEnd'
../lib/libzip.so.5.0: undefined reference to `inflateInit2_'
collect2: error: ld returned 1 exit status
regress/CMakeFiles/ziptool_regress.dir/build.make:121: recipe for target 'regress/ziptool_regress' failed
make[2]: *** [regress/ziptool_regress] Error 1
CMakeFiles/Makefile2:689: recipe for target 'regress/CMakeFiles/ziptool_regress.dir/all' failed
make[1]: *** [regress/CMakeFiles/ziptool_regress.dir/all] Error 2
Makefile:138: recipe for target 'all' failed
make: *** [all] Error 2

似乎 cmake 无法找到已编译的 zlib 库,即使路径似乎配置良好(或没有?)。

有人在使用 libzip 时遇到过类似的问题吗?是否有任何附加的 cmake 宏可以解决这个问题?

- - 更新 - -

我实际上摆脱了这个错误抑制构建任务zipcmp, 压缩合并压缩工具(因为我不需要它们)评论这些行:

#ADD_EXECUTABLE(zipcmp zipcmp.c ${SRC_EXTRA_FILES})
#TARGET_LINK_LIBRARIES(zipcmp zip)
#INSTALL(TARGETS zipcmp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

#ADD_EXECUTABLE(zipmerge zipmerge.c ${SRC_EXTRA_FILES})
#TARGET_LINK_LIBRARIES(zipmerge zip)
#INSTALL(TARGETS zipmerge RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

#ADD_EXECUTABLE(ziptool ziptool.c ${SRC_EXTRA_FILES})
#TARGET_LINK_LIBRARIES(ziptool zip)
#INSTALL(TARGETS ziptool RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

进入src/CMakeLists.txt。然后我使用make -j 8 zip然后编译了库make install/fast。它仍然返回错误

Install the project...
-- Install configuration: ""
-- Installing: /home/simo/adtdev/Var_libs/libzip-1.5.1/build_armhf64/install/lib/pkgconfig/libzip.pc
-- Installing: /home/simo/adtdev/Var_libs/libzip-1.5.1/build_armhf64/install/include/zipconf.h
-- Installing: /home/simo/adtdev/Var_libs/libzip-1.5.1/build_armhf64/install/include/zip.h
-- Installing: /home/simo/adtdev/Var_libs/libzip-1.5.1/build_armhf64/install/lib/libzip.a
CMake Error at man/cmake_install.cmake:36 (file):
  file INSTALL cannot find
  "/home/simo/adtdev/Var_libs/libzip-1.5.1/build_armhf64/man/ZIP_SOURCE_GET_ARGS.3".
Call Stack (most recent call first):
  cmake_install.cmake:46 (include)


Makefile:89: recipe for target 'install/fast' failed
make: *** [install/fast] Error 1

但我不关心它,因为我已经在安装目录中安装了库和标头,而这正是我所需要的。

答案1

# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)

# specify the cross compiler
SET(CMAKE_C_COMPILER   /your/toolchain/path/bin/yourcompile-gcc)
SET(CMAKE_CXX_COMPILER /your/toolchain/path/bin/yourcompile-g++)

# where is the target environment 
SET(CMAKE_FIND_ROOT_PATH  /your/rootfs/path)

# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

相关内容