Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing symbols when linking statically on macOS: SecRandomCopyBytes, _compression_stream_init #791

Closed
yay opened this issue Jul 22, 2024 · 5 comments
Labels
build system Build system and script changes

Comments

@yay
Copy link

yay commented Jul 22, 2024

I'm trying to link statically into an Odin executable, building minizip-ng with the following flags:

/Users/vitaly/projects/minizip-ng $ cmake -S . -B build -D MZ_BUILD_TESTS=ON -D MZ_COMPAT=OFF -D MZ_ZLIB=ON -D MZ_BZIP2=OFF -D MZ_LZMA=OFF -D MZ_ZSTD=OFF -D MZ_FETCH_LIBS=ON -D MZ_FORCE_FETCH_LIBS=ON -D MZ_PKCRYPT=ON -D MZ_WZAES=OFF -D MZ_OPENSSL=OFF -D MZ_LIBBSD=ON -D MZ_ICONV=OFF -D MZ_COMPRESS_ONLY=OFF -D MZ_DECOMPRESS_ONLY=ON -D MZ_FILE32_API=OFF -D MZ_BUILD_UNIT_TESTS=OFF -D MZ_BUILD_FUZZ_TESTS=OFF -D MZ_CODE_COVERAGE=OFF
-- The C compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Using CMake version 3.30.1
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for inttypes.h
-- Looking for inttypes.h - found
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- Looking for fseeko
-- Looking for fseeko - found
-- Using CoreFoundation Framework
-- Using Security Framework
-- Looking for CommonCrypto/CommonCrypto.h
-- Looking for CommonCrypto/CommonCrypto.h - found
-- Using CommonCrypto
-- Looking for getrandom
-- Looking for getrandom - not found
-- Looking for arc4random_buf
-- Looking for arc4random_buf - found
-- Character encoding support requires iconv
-- The following features have been enabled:

 * MZ_LIBCOMP, Enables Apple compression
 * MZ_FETCH_LIBS, Enables fetching third-party libraries if not found
 * MZ_FORCE_FETCH_LIBS, Enables fetching third-party libraries always
 * MZ_PKCRYPT, Enables PKWARE traditional encryption
 * MZ_DECOMPRESS_ONLY, Only support decompression
 * MZ_BUILD_TESTS, Builds minizip test executable

-- The following features have been disabled:

 * MZ_COMPAT, Enables compatibility layer
 * MZ_ZLIB, Enables ZLIB compression
 * MZ_BZIP2, Enables BZIP2 compression
 * MZ_LZMA, Enables LZMA & XZ compression
 * MZ_ZSTD, Enables ZSTD compression
 * MZ_WZAES, Enables WinZIP AES encryption
 * MZ_OPENSSL, Enables OpenSSL for encryption
 * MZ_LIBBSD, Builds with libbsd crypto random
 * MZ_ICONV, Enables iconv string encoding conversion library
 * MZ_COMPRESS_ONLY, Only support compression
 * MZ_FILE32_API, Builds using posix 32-bit file api
 * MZ_BUILD_UNIT_TESTS, Builds minizip unit test project
 * MZ_BUILD_FUZZ_TESTS, Builds minizip fuzzer executables
 * MZ_CODE_COVERAGE, Builds with code coverage flags

-- Configuring done (1.1s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/vitaly/projects/minizip-ng/build
/Users/vitaly/projects/minizip-ng $ cmake --build build 
[  6%] Building C object CMakeFiles/minizip-ng.dir/mz_crypt.c.o
[ 12%] Building C object CMakeFiles/minizip-ng.dir/mz_os.c.o
[ 18%] Building C object CMakeFiles/minizip-ng.dir/mz_strm.c.o
[ 25%] Building C object CMakeFiles/minizip-ng.dir/mz_strm_buf.c.o
[ 31%] Building C object CMakeFiles/minizip-ng.dir/mz_strm_mem.c.o
[ 37%] Building C object CMakeFiles/minizip-ng.dir/mz_strm_split.c.o
[ 43%] Building C object CMakeFiles/minizip-ng.dir/mz_zip.c.o
[ 50%] Building C object CMakeFiles/minizip-ng.dir/mz_zip_rw.c.o
[ 56%] Building C object CMakeFiles/minizip-ng.dir/mz_strm_libcomp.c.o
[ 62%] Building C object CMakeFiles/minizip-ng.dir/mz_os_posix.c.o
[ 68%] Building C object CMakeFiles/minizip-ng.dir/mz_strm_os_posix.c.o
[ 75%] Building C object CMakeFiles/minizip-ng.dir/mz_crypt_apple.c.o
[ 81%] Building C object CMakeFiles/minizip-ng.dir/mz_strm_pkcrypt.c.o
[ 87%] Linking C static library libminizip-ng.a
[ 87%] Built target minizip-ng
[ 93%] Building C object CMakeFiles/minizip_cli.dir/minizip.c.o
[100%] Linking C executable minizip
[100%] Built target minizip_cli

but building the target Odin executable I get the following errors:

Undefined symbols for architecture arm64:
  "_SecRandomCopyBytes", referenced from:
      _mz_crypt_rand in libminizip-ng.a[13](mz_crypt_apple.c.o)
  "_compression_stream_destroy", referenced from:
      _mz_stream_libcomp_close in libminizip-ng.a[10](mz_strm_libcomp.c.o)
  "_compression_stream_init", referenced from:
      _mz_stream_libcomp_open in libminizip-ng.a[10](mz_strm_libcomp.c.o)
  "_compression_stream_process", referenced from:
      _mz_stream_libcomp_read in libminizip-ng.a[10](mz_strm_libcomp.c.o)
  "_kSecRandomDefault", referenced from:
      _mz_crypt_rand in libminizip-ng.a[13](mz_crypt_apple.c.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

On Windows, I am able to use minizip-ng with no issues, and don't run into _mz_stream_libcomp errors.
I also realize _SecRandomCopyBytes and _kSecRandomDefault are macOS specific, but don't know why I'm getting these errors on a mac.

I've tried various combination of build flags, but I still get at least these 5 symbol errors. The only thing I need minizip-ng to do is to unzip unencrypted archives. Am I missing something?

@Nekto89
Copy link

Nekto89 commented Jul 22, 2024

You need to link to several frameworks on Apple.
CoreFoundation, Security
https://github.com/zlib-ng/minizip-ng/blob/fe5fedc365f7824ada0cf9a84fb79b30d5fc97a8/CMakeLists.txt#L474C16-L491C39

@yay
Copy link
Author

yay commented Jul 22, 2024

@Nekto89 That worked, thanks! But I'm still seeing the remaining three:

Undefined symbols for architecture arm64:
  "_compression_stream_destroy", referenced from:
      _mz_stream_libcomp_close in libminizip-ng.a[10](mz_strm_libcomp.c.o)
  "_compression_stream_init", referenced from:
      _mz_stream_libcomp_open in libminizip-ng.a[10](mz_strm_libcomp.c.o)
  "_compression_stream_process", referenced from:
      _mz_stream_libcomp_read in libminizip-ng.a[10](mz_strm_libcomp.c.o)
ld: symbol(s) not found for architecture arm64

Any thoughts on how to fix these?

@Nekto89
Copy link

Nekto89 commented Jul 22, 2024 via email

@yay
Copy link
Author

yay commented Jul 22, 2024

list(APPEND MINIZIP_LIB compression)
try compression library

On Mon, 22 Jul 2024, 21:47 Vitaly Kravchenko, @.> wrote: @Nekto89 https://github.com/Nekto89 That worked, thanks! But I'm still seeing the remaining three: Undefined symbols for architecture arm64: "_compression_stream_destroy", referenced from: _mz_stream_libcomp_close in libminizip-ng.a10 "_compression_stream_init", referenced from: _mz_stream_libcomp_open in libminizip-ng.a10 "_compression_stream_process", referenced from: _mz_stream_libcomp_read in libminizip-ng.a10 ld: symbol(s) not found for architecture arm64 Any thoughts on how to fix these? — Reply to this email directly, view it on GitHub <#791 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAUCRBUIBO5JPQOA5JO4K3ZNVHVVAVCNFSM6AAAAABLIAKHWGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDENBTGYYDAOBUGA . You are receiving this because you were mentioned.Message ID: @.>

Not sure I understand. I already use MZ_LIBCOMP flag:

-- The following features have been enabled:

 * MZ_LIBCOMP, Enables Apple compression

Should I add something else to the cmake -S . -B build flags?

@yay
Copy link
Author

yay commented Jul 22, 2024

Ah, got it, #478
MZ_LIBCOMP actually had to be disabled in my case.
@Nekto89 Thanks a lot for the help!

@yay yay closed this as completed Jul 22, 2024
@nmoinvaz nmoinvaz added the build system Build system and script changes label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build system Build system and script changes
Projects
None yet
Development

No branches or pull requests

3 participants