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

Unresolved external symbol(s) when trying to link clamav applications #990

Closed
driverxdw opened this issue Aug 8, 2023 · 4 comments · Fixed by #992
Closed

Unresolved external symbol(s) when trying to link clamav applications #990

driverxdw opened this issue Aug 8, 2023 · 4 comments · Fixed by #992

Comments

@driverxdw
Copy link
Contributor

Describe the bug

environment:
host: x64-win10
compiler: msvc(vs2022)
clamav: v1.1.0

I used vcpkg + cmake to compile clamav on windows according to the clamav documentation, but finally reported an error when linking each application clamav application like this:

PS C:\Users\xdw\Desktop\clamav-1.1.0\build> cmake --build . -j16
MSBuild version 17.6.3+07e294721 for .NET Framework

  bytecode_runtime.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\bytecode_runtime.dir\Debug\bytecode_runtime.lib
  regex.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\regex.dir\Debug\regex.lib
  win32_compat_obj.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\win32\compat\win32_compat_obj.dir\Debug\win32_compat_obj.lib
  yara.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\yara.dir\Debug\yara.lib
  lzma_sdk.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\lzma_sdk.dir\Debug\lzma_sdk.lib
  win32_compat.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\win32\compat\Debug\libwin32_compat.lib
  Auto build dll exports
  Auto build dll exports
  clammspack.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclammspack\Debug\libclammspack.dll
  clamunrar.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamunrar\Debug\libclamunrar.dll
  Auto build dll exports
  clamunrar_iface.vcxproj -> C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamunrar_iface\Debug\libclamunrar_iface.dll
  Auto build dll exports
     Creating library C:/Users/xdw/Desktop/clamav-1.1.0/build/libclamav/Debug/clamav.lib and object C:/Users/xdw/Desktop/clamav-1.1.0/build/libclamav/Debug/clamav.exp
LINK : warning LNK4217: symbol 'inflate64' defined in 'inflate64.obj' is imported by 'unzip.obj' in function 'unz' [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
LINK : warning LNK4217: symbol 'inflate64End' defined in 'inflate64.obj' is imported by 'unzip.obj' in function 'unz' [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
LINK : warning LNK4217: symbol 'inflate64Init2' defined in 'inflate64.obj' is imported by 'unzip.obj' in function 'unz' [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_NtCreateFile referenced in function _ZN3std3sys7windows2fs20open_link_no_reparse17h8e579f91ed4cd98
2E [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_RtlNtStatusToDosError referenced in function _ZN3std3sys7windows2fs20open_link_no_reparse17h8e579f
91ed4cd982E [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_NtReadFile referenced in function _ZN3std3sys7windows6handle6Handle16synchronous_read17hfa39d6a5f1
7db40dE [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_NtWriteFile referenced in function _ZN3std3sys7windows6handle6Handle17synchronous_write17h017470e7
d9d95434E [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]
C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\Debug\libclamav.dll : fatal error LNK1120: 4 unresolved externals [C:\Users\xdw\Desktop\clamav-1.1.0\build\libclamav\clamav.vcxproj]

And If add the -DENABLE_APP=OFF option, i can compile successfully.

How to reproduce the problem

  1. install vs
  2. install dependent libraries through vcpkg like this:
vcpkg.exe install 'curl[openssl]' 'json-c' 'libxml2' 'pcre2' 'pthreads' 'zlib' 'pdcurses' 'bzip2' 'check'
  1. configure & build
cmake .. -D CMAKE_BUILD_TYPE="Debug" -D CMAKE_TOOLCHAIN_FILE="$VCPKG_PATH\scripts\buildsystems\vcpkg.cmake" -D ENABLE_TESTS=OFF  -D VCPKG_TARGET_TRIPLET=x64-windows
  1. build
cmake --build . -j16

@micahsnyder
Copy link
Contributor

I was initially unable to reproduce this error when I just tried with the latest from the main branch.

I did a search and stumbled across corrosion-rs/corrosion#418 where they encountered the same sort of issue. It appears something changed in Cargo that broke linking with the native static libraries on Windows.

I ran rustup update to get the latest version of Cargo and tried again and ran into the same errors you reported:

...
  libclamav_main.c
  Generating Code...
  Auto build dll exports
     Creating library C:/Users/micah/workspace/clamav-micah/build/libclamav/Debug/clamav.lib and object C:/Users/micah/workspace/clamav-micah/build/libclamav/Debug/clamav.exp
LINK : warning LNK4217: symbol 'inflate64' defined in 'inflate64.obj' is imported by 'unzip.obj' in function 'unz' [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vcxproj]
LINK : warning LNK4217: symbol 'inflate64End' defined in 'inflate64.obj' is imported by 'unzip.obj' in function 'unz' [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vcxproj]
LINK : warning LNK4217: symbol 'inflate64Init2' defined in 'inflate64.obj' is imported by 'unzip.obj' in function 'unz' [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_NtCreateFile referenced in function _ZN3std3sys7windows2fs20open_link_no_reparse17h8e579f91ed4cd982E [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_RtlNtStatusToDosError referenced in function _ZN3std3sys7windows2fs20open_link_no_reparse17h8e579f91ed4cd982E [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.
vcxproj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_NtReadFile referenced in function _ZN3std3sys7windows6handle6Handle16synchronous_read17hfa39d6a5f17db40dE [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vcxp
roj]
clamav_rust.lib(std-4e8f46f7d0c95848.std.8cc7dfd4267f2efd-cgu.0.rcgu.o) : error LNK2019: unresolved external symbol __imp_NtWriteFile referenced in function _ZN3std3sys7windows6handle6Handle17synchronous_write17h017470e7d9d95434E [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vc
xproj]
C:\Users\micah\workspace\clamav-micah\build\libclamav\Debug\libclamav.dll : fatal error LNK1120: 4 unresolved externals [C:\Users\micah\workspace\clamav-micah\build\libclamav\clamav.vcxproj]

micahsnyder added a commit to micahsnyder/clamav-micah that referenced this issue Aug 9, 2023
Some change in Cargo/Rust version 1.70 or 1.71 appears to have broken
the build on Windows because we are incorrectly attempting to check the
native static libraries by compiling an empty file (/dev/null) which
does not exist on Windows.

A simple fix is to make an empty file of our own and use that instead.

Fixes: Cisco-Talos#990
@micahsnyder
Copy link
Contributor

It looks like whatever change happened in cargo/rustc version 1.70 or 1.71 exposed an issue in our CMakeRust.cmake module where we're testing what the native-static-libs are using /dev/null, which does not exist on Windows.

@driverxdw
Copy link
Contributor Author

It looks like whatever change happened in cargo/rustc version 1.70 or 1.71 exposed an issue in our CMakeRust.cmake module where we're testing what the native-static-libs are using /dev/null, which does not exist on Windows.

Thanks!

@aktiwari22
Copy link

It worked with your changes. Thanks

micahsnyder added a commit to micahsnyder/clamav-micah that referenced this issue Aug 9, 2023
Some change in Cargo/Rust version 1.70 or 1.71 appears to have broken
the build on Windows because we are incorrectly attempting to check the
native static libraries by compiling an empty file (/dev/null) which
does not exist on Windows.

A simple fix is to make an empty file of our own and use that instead.

Fixes: Cisco-Talos#990
micahsnyder added a commit to micahsnyder/clamav-micah that referenced this issue Aug 9, 2023
Some change in Cargo/Rust version 1.70 or 1.71 appears to have broken
the build on Windows because we are incorrectly attempting to check the
native static libraries by compiling an empty file (/dev/null) which
does not exist on Windows.

A simple fix is to make an empty file of our own and use that instead.

Fixes: Cisco-Talos#990
micahsnyder added a commit that referenced this issue Aug 9, 2023
Some change in Cargo/Rust version 1.70 or 1.71 appears to have broken
the build on Windows because we are incorrectly attempting to check the
native static libraries by compiling an empty file (/dev/null) which
does not exist on Windows.

A simple fix is to make an empty file of our own and use that instead.

Fixes: #990
micahsnyder added a commit that referenced this issue Aug 9, 2023
Some change in Cargo/Rust version 1.70 or 1.71 appears to have broken
the build on Windows because we are incorrectly attempting to check the
native static libraries by compiling an empty file (/dev/null) which
does not exist on Windows.

A simple fix is to make an empty file of our own and use that instead.

Fixes: #990
micahsnyder added a commit that referenced this issue Aug 9, 2023
Some change in Cargo/Rust version 1.70 or 1.71 appears to have broken
the build on Windows because we are incorrectly attempting to check the
native static libraries by compiling an empty file (/dev/null) which
does not exist on Windows.

A simple fix is to make an empty file of our own and use that instead.

Fixes: #990
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants