Bug 106088 - ld cannot find dependent libraries when cross compiling
Summary: ld cannot find dependent libraries when cross compiling
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 10.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-06-26 10:01 UTC by William Tang
Modified: 2022-06-27 10:45 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description William Tang 2022-06-26 10:01:40 UTC
Cross compiling the following program using command "arm-linux-gnueabihf-gcc main.c -lz" works without any issues:

#include <stdio.h>
#include <zlib.h>

int main(int argc, char const *argv[])
{
	z_stream s;
	inflateSync(&s);
	return 0;
}

However, if the linked library has dependencies, the ld program seems not be able to find them.  e.g. compiling the following program using command "arm-linux-gnueabihf-gcc main.c -larchive":

#include <stdio.h>
#include <archive.h>

int main(int argc, char const *argv[])
{
	puts(archive_zlib_version());
	return 0;
}

gives error:

/usr/bin/arm-linux-gnueabihf-ld: warning: libcrypto.so.1.1, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: libacl.so.1, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: libexpat.so.1, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: liblzma.so.5, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: libzstd.so.1, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: liblz4.so.1, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: libbz2.so.1.0, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: warning: libz.so.1, needed by /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so, not found (try using -rpath or -rpath-link)
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_stream_encoder_mt@XZ_5.2'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `inflateReset'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_code@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_raw_encoder@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_stream_decoder@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_decompress_safe_usingDict'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_qualifier@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_freeStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_clear_perms@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `XML_ParserCreate'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_compress_HC'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `inflateEnd'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_entry@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_CIPHER_CTX_new@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_sha384@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_CCtx_setParameter'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_DigestUpdate@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_properties_size@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_isError'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_lzma_preset@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzCompressInit'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_loadDict'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `deflate'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_fd@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_maxCLevel'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `deflateInit_'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `HMAC_Init_ex@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `PKCS5_PBKDF2_HMAC_SHA1@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `XML_SetUserData'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_CIPHER_CTX_free@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_MD_CTX_free@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzCompress'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_sha1@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_initCStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_raw_decoder@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_permset@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_saveDict'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_saveDictHC'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `inflateInit2_'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_compress_default'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_createCStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `inflate'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_add_perm@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_alone_encoder@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `crc32'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `deflateEnd'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_createDStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_create_entry@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `deflateReset'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_file@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_compress_HC_continue'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_sha256@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_set_file@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_decompressStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzDecompress'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `HMAC_CTX_free@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_CStreamOutSize'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_loadDictHC'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_createStreamHC'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `inflateSetDictionary'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_createStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_freeDStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_freeCStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_MD_CTX_new@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_freeStreamHC'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_aes_128_ecb@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_cputhreads@XZ_5.2'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_aes_256_ecb@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_getErrorName'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_free@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_decompress_safe'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_perm@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_compress_fast_continue'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_aes_192_ecb@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_get_tag_type@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_properties_encode@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzDecompressEnd'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_compressStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_DigestInit@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `HMAC_CTX_new@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_end@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `inflateInit_'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_alone_decoder@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `XML_ParserFree'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_endStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `deflateInit2_'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_minCLevel'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_EncryptUpdate@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_init@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_md5@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `XML_SetElementHandler'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `XML_Parse'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_DStreamOutSize'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_crc32@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_EncryptInit_ex@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_set_tag_type@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `LZ4_resetStreamHC'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_ripemd160@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_DigestFinal@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `EVP_sha512@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_memusage@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `HMAC_Final@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzDecompressInit'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `XML_SetCharacterDataHandler'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_properties_decode@XZ_5.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `HMAC_Update@OPENSSL_1_1_0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_initDStream'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzlibVersion'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `ZSTD_versionNumber'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_set_fd@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `acl_set_qualifier@ACL_1.0'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `BZ2_bzCompressEnd'
/usr/bin/arm-linux-gnueabihf-ld: /usr/lib/gcc/arm-linux-gnueabihf/10.2.0/../../../../arm-linux-gnueabihf/lib/libarchive.so: undefined reference to `lzma_stream_encoder@XZ_5.0'
collect2: error: ld returned 1 exit status


GCC Version:

Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/10.2.0/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /build/arm-linux-gnueabihf-gcc/src/gcc/configure --prefix=/usr --program-prefix=arm-linux-gnueabihf- --with-local-prefix=/usr/arm-linux-gnueabihf --with-sysroot=/usr/arm-linux-gnueabihf --with-build-sysroot=/usr/arm-linux-gnueabihf --with-as=/usr/bin/arm-linux-gnueabihf-as --with-ld=/usr/bin/arm-linux-gnueabihf-ld --libdir=/usr/lib --libexecdir=/usr/lib --disable-nls --enable-languages=c,c++,fortran,lto,objc,obj-c++ --with-isl --with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit --enable-checking=release --enable-clocale=gnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object --enable-install-libiberty --enable-linker-build-id --enable-lto --enable-plugin --enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch --disable-libunwind-exceptions --disable-multilib --disable-werror --target=arm-linux-gnueabihf --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --enable-interwork --enable-addons --with-arch=armv6 --with-float=hard --with-fpu=vfp
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.2.0 (GCC)
Comment 1 William Tang 2022-06-26 10:07:06 UTC
The mentioned libraries did exist in the cross compile environment.  Compiling with command "arm-linux-gnueabihf-gcc main.c -Wl,-rpath-link,/usr/arm-linux-gnueabihf/usr/lib -larchive" works just fine.
Comment 2 Xi Ruoyao 2022-06-26 10:20:28 UTC
It means you've misconfigured ld.  GCC has nothing to do with tracking DT_NEEDED entries in ELF shared objects.
Comment 3 William Tang 2022-06-26 13:41:08 UTC
Thanks, you are right, somehow, the ld of binutils has the wrong default SEARCH_DIR:

[william@NoteBook ~]$ arm-linux-gnueabihf-ld --verbose | grep SEARCH
SEARCH_DIR("/usr/lib/binutils/arm-linux-gnueabihf"); SEARCH_DIR("=/usr/arm-linux-gnueabihf/lib");

Created a bug for binutils: https://sourceware.org/bugzilla/show_bug.cgi?id=29288
Comment 4 William Tang 2022-06-26 17:12:23 UTC
Okay, the '=' before search dir denotes sysroot replacement (https://sourceware.org/binutils/docs/ld/Options.html), so the configuration of ld should be correct.  Anyway, it should be a binutils issue.
Comment 5 Richard Biener 2022-06-27 10:45:22 UTC
Thus moved.