错误消息:在 C 上编译 ARM 时出现未定义的链接 «crc32»。

huangapple go评论79阅读模式
英文:

Error message compiling ARM on C: undefined link to «crc32»

问题

I try to compile for ARM 32bit a C project, which contains links to zlib & minizip static libraries. I work with CLion IDE on Ubuntu 20. I had installed toolchain:

sudo apt-get install gcc-arm-linux-gnueabihf

Then I downloaded ARM deb packages, from which I extracted libz.a & libminizip.a:

zlib1g-dev_1.2.11.dfsg-2ubuntu1_armhf.deb
libminizip-dev_1.1-8build1_armhf.deb

Then I try to compile, but have:

====================[ Build | all | Default-System ]============================
/home/user/external/clion-2023.1.1/bin/cmake/linux/x64/bin/cmake --build /home/user/Clion/myproject/cmake-build-default-system --target all -j 1
[3/3] Linking C executable updater
FAILED: updater 
: && /usr/bin/arm-linux-gnueabihf-gcc -fsanitize=address  CMakeFiles/updater.dir/main.c.o CMakeFiles/updater.dir/base64.c.o -o updater  /home/user/Clion/myproject/lib/arm/libz.a  /home/user/Clion/myproject/lib/arm/libminizip.a  /home/user/Clion/myproject/lib/arm/libjansson.a && :
/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /home/user/Clion/myproject/lib/arm/libminizip.a(unzip.o): in function 'unzReadCurrentFile':
(.text+0x144e): undefined link to 'crc32'

Here is CmakeLists.txt:

cmake_minimum_required(VERSION 3.17)
project(updater C)

set(CMAKE_C_STANDARD 99)

add_executable(updater main.c unpack.h)


set(ZLIB_INCLUDE_DIR /home/user/Clion/myproject/zlib-arm/include)
set(ZLIB_LIBRARY /home/user/Clion/myproject/lib/arm/libz.a)
set(MINIZIP_LIBRARY /home/user/Clion/myproject/lib/arm/libminizip.a)
target_include_directories(updater PRIVATE ${ZLIB_INCLUDE_DIR})
target_link_libraries(updater PRIVATE ${ZLIB_LIBRARY})
target_link_libraries(updater PRIVATE ${MINIZIP_LIBRARY})

The survey of the libz.a seems OK:

nm /home/user/Clion/myproject/lib/arm/libz.a | grep crc32
crc32.o:
00000645 T crc32
0000064d T crc32_combine
00000481 t crc32_combine_
00000651 T crc32_combine64
00000001 t crc32_little
0000063d T crc32_z
         U crc32
         U crc32

I suspect that downloaded libraries might be incompatible. But what to replace them with?
Or build them manually - but how?
Any advice?

英文:

I try to compile for ARM 32bit a C project, which contains links to zlib & minizip static libraries. I work with CLion IDE on Ubuntu 20. I had installed toolchain:

sudo apt-get install gcc-arm-linux-gnueabihf

Then I downloaded ARM deb packages, from which I extracted libz.a & libminizip.a:

zlib1g-dev_1.2.11.dfsg-2ubuntu1_armhf.deb
libminizip-dev_1.1-8build1_armhf.deb

Then I try to compile, but have:

====================[ Build | all | Default-System ]============================
/home/user/external/clion-2023.1.1/bin/cmake/linux/x64/bin/cmake --build /home/user/Clion/myproject/cmake-build-default-system --target all -j 1
[3/3] Linking C executable updater
FAILED: updater 
: && /usr/bin/arm-linux-gnueabihf-gcc -fsanitize=address  CMakeFiles/updater.dir/main.c.o CMakeFiles/updater.dir/base64.c.o -o updater  /home/user/Clion/myproject/lib/arm/libz.a  /home/user/Clion/myproject/lib/arm/libminizip.a  /home/user/Clion/myproject/lib/arm/libjansson.a && :
/usr/lib/gcc-cross/arm-linux-gnueabihf/9/../../../../arm-linux-gnueabihf/bin/ld: /home/user/Clion/myproject/lib/arm/libminizip.a(unzip.o): in function «unzReadCurrentFile»:
(.text+0x144e): undefined link to «crc32»

Here is CmakeLists.txt:

cmake_minimum_required(VERSION 3.17)
project(updater C)

set(CMAKE_C_STANDARD 99)

add_executable(updater main.c unpack.h)


set(ZLIB_INCLUDE_DIR /home/user/Clion/myproject/zlib-arm/include)
set(ZLIB_LIBRARY /home/user/Clion/myproject/lib/arm/libz.a)
set(MINIZIP_LIBRARY /home/user/Clion/myproject/lib/arm/libminizip.a)
target_include_directories(updater PRIVATE ${ZLIB_INCLUDE_DIR})
target_link_libraries(updater PRIVATE ${ZLIB_LIBRARY})
target_link_libraries(updater PRIVATE ${MINIZIP_LIBRARY})

The survey of the libz.a seems OK:

nm /home/user/Clion/myproject/lib/arm/libz.a | grep crc32
crc32.o:
00000645 T crc32
0000064d T crc32_combine
00000481 t crc32_combine_
00000651 T crc32_combine64
00000001 t crc32_little
0000063d T crc32_z
         U crc32
         U crc32

I suspect that downloaded libraries might be incompatible. But what to replace them with?
Or build them manually - but how?
Any advice?

答案1

得分: 1

你的链接命令:

arm-linux-gnueabihf-gcc ... libz.a libminizip.a ...

是不正确的:因为 libminzip.a 需要来自 libz.a 的符号,所以它应该在链接命令中位于 libz.a 之前。

要更好地理解这一点,请阅读此文章

英文:

Your link command:

arm-linux-gnueabihf-gcc ... libz.a libminizip.a ...

is incorrect: since libminzip.a requires symbols from libz.a, it should be before libz.a on the link line.

To understand this better, read this post.

huangapple
  • 本文由 发表于 2023年4月11日 09:40:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75981840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定