1

I am trying to cross compile libzip-1.5.1 having previously successfully complied zlib-1.2.11 (these are required by libzip and I have installed in a local home path), but I am experiencing problems with the cmake's process.

The script I use to build and compile (from a build directory into the libzip's sources folder) is the following:

#!/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

But at 94 % of building process, I get the following errors:

[ 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

It seems that cmake cannot find the compiled zlib libraries, even if the paths seems to be well configured (or not ?).

Do some has experienced similar issues with libzip ? Is there any addition cmake's macro that would solve this issue ?

---- UPDATE ----

I actually get rid of this error suppressing building task for zipcmp, zipmerge and ziptool (since I don't need them) commenting the lines:

#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})

into src/CMakeLists.txt. Then I compiled the libs using make -j 8 zip and then make install/fast. It still returns the error

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

but I don't care about it since I have the libs and headers installed in the install dir, and this is what I need.

0
# 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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.