zlib-ng / minizip-ng

Fork of the popular zip manipulation library found in the zlib distribution.
Other
1.25k stars 434 forks source link

link error when changing cmake library output directory #803

Closed toodemhard closed 1 month ago

toodemhard commented 1 month ago

I can build with this normally but when setting CMAKE_LIBRARY_OUTPUT_DIRECTORY or trying to include this library as part of an install it causes a link error.

The build for this library is quite unstable and sometimes even reconfigure cmake can break it so maybe something wrong with the cmake files like some hardcoded paths?

FAILED: lib/elzip/elzip.dll lib/elzip/elzip.lib
C:\Windows\system32\cmd.exe /C "cd . && C:\PROGRA~1\MICROS~3\2022\COMMUN~1\VC\Tools\Llvm\x64\bin\CLANG_~1.EXE -nostartfiles -nostdlib -Wno-error -O3 -DNDEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrt  -fuse-ld=lld-link -shared -o lib\elzip\elzip.dll  -Xlinker /MANIFEST:EMBED -Xlinker /implib:lib\elzip\elzip.lib -Xlinker /pdb:lib\elzip\elzip.pdb -Xlinker /version:0.0 lib/elzip/CMakeFiles/elzip.dir/src/elzip.cpp.obj lib/elzip/CMakeFiles/elzip.dir/src/unzipper.cpp.obj lib/elzip/CMakeFiles/elzip.dir/src/zipper.cpp.obj  lib/elzip/extlibs/minizip/minizip.lib  -lbcrypt.lib  -lncrypt.lib  -lcrypt32.lib  _deps/zlib-build/zlib-ng.lib  -lkernel32 -luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid -lcomdlg32 -ladvapi32 -loldnames  && cd ."
lld-link: error: undefined symbol: mz_path_resolve
>>> referenced by lib/elzip/CMakeFiles/elzip.dir/src/elzip.cpp.obj:(class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> __cdecl elz::_resolvePath(class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>> const &))
CLANG_~1: error: linker command failed with exit code 1 (use -v to see invocation)
[2/5] C:\Windows\system32\cmd.exe /C "cd /D C:\Users\toodemhard\projects\games\taiko\build\dis...rd/projects/games/taiko/data C:/Users/toodemhard/projects/games/taiko/build/distribution/data"
ninja: build stopped: subcommand failed.

When this error occurs the minizip.lib just has no symbols whereas it does in working build.

dumpbin /SYMBOLS .\minizip.lib
Microsoft (R) COFF/PE Dumper Version 14.41.34120.0
Copyright (C) Microsoft Corporation.  All rights reserved.

Dump of file .\minizip.lib

File Type: LIBRARY

COFF SYMBOL TABLE
000 00000000 SECT1  notype       External     | __IMPORT_DESCRIPTOR_minizip
001 00000000 SECT1  notype       Section      | .idata$2
002 00000000 SECT2  notype       Static       | .idata$6
003 00000000 UNDEF  notype       Section      | .idata$4
004 00000000 UNDEF  notype       Section      | .idata$5
005 00000000 UNDEF  notype       External     | __NULL_IMPORT_DESCRIPTOR
006 00000000 UNDEF  notype       External     | minizip_NULL_THUNK_DATA

String Table Size = 0x52 bytes

COFF SYMBOL TABLE
000 00000000 SECT1  notype       External     | __NULL_IMPORT_DESCRIPTOR

String Table Size = 0x1D bytes

COFF SYMBOL TABLE
000 00000000 SECT1  notype       External     | minizip_NULL_THUNK_DATA

String Table Size = 0x1D bytes

  Summary

          14 .idata$2
          14 .idata$3
           8 .idata$4
           8 .idata$5
           C .idata$6

Causes:

install(DIRECTORY ${CMAKE_SOURCE_DIR}/data/ DESTINATION ${CMAKE_INSTALL_PREFIX}/data)



I'm using minizip indirectly as part of https://github.com/Sygmei/11Zip but their CMakelists.txt is very simple and I can't find a problem with it. When linking vendored minizip directly with add_subdirectory() and target_link_libraries() I also get link errors so I'm pretty sure its this lib causing it.
toodemhard commented 1 month ago

Btw im using a fork with latest version of minizip https://github.com/toodemhard/11Zip. I know some other build issues were fixed previously.

nmoinvaz commented 1 month ago

What do you propose? Have you tried -D BUILD_SHARED_LIBS=OFF?

toodemhard commented 1 month ago

Yea setting BUILD_SHARED_LIBS=OFF fixes it. I think the reason is that I want to output all my dlls next to the exe but minizip expects the zlib dll to be somewhere else. It's probably just my bad usage of indiscriminately changing the library output dir so feel free to close this.

I managed to hack around the issue when building shared libs by using cmake to copy the dlls to next to the exe post build and instead of using install i just copy all the files to a distribution directory. I think I'm going to keep using the copy hack for distribution anyways because I cant get install() to install my libs.

nmoinvaz commented 1 month ago

Sorry I couldn't help more. I'm just not an expert at package distribution with CMake.