Reproduction steps:
cd example-ffi
cargo capi install --prefix build
The build
subdir of example-ffi
should now contain:
bin/
withexample-ffi.dll
andexmaple-ffi.pdb
include/
withexample-ffi.h
lib/
withexample-ffi.def
,example-ffi.dll.lib
andexample.ffi.lib
(as well as apkgconfig
subdir)
- Update
example-c/CMakeLists.txt
to set thefind_library
directory path to the location you cloned this repo. e.g.
find_library(EXAMPLE_FFI_LIB example-ffi
PATHS "C:/Users/danie/Code/Rust/example-ffi/example-ffi/build/lib"
REQUIRED
)
- Run the build:
cd example-c
cmake -S . -B build
cmake --build build
- Observe the error output:
PS C:\Users\danie\Code\Rust\example-ffi\example-c> cmake -S . -B build
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.41.34123.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Found example-ffi library: C:/Users/danie/Code/Rust/example-ffi/example-ffi/build/lib/example-ffi.dll.lib
-- Configuring done (2.0s)
-- Generating done (0.0s)
-- Build files have been written to: C:/Users/danie/Code/Rust/example-ffi/example-c/build
PS C:\Users\danie\Code\Rust\example-ffi\example-c> cmake --build build
MSBuild version 17.11.9+a69bbaaf5 for .NET Framework
1>Checking Build System
Building Custom Rule C:/Users/danie/Code/Rust/example-ffi/example-c/CMakeLists.txt
main.c
C:\Users\danie\Code\Rust\example-ffi\example-ffi\build\lib\example-ffi.dll.lib : fatal error LNK1127: library is corrupt [C:\Us
ers\danie\Code\Rust\example-ffi\example-c\build\example-c.vcxproj]
- Optionally, confirm with
dumpbin
:
cd example-c\build\lib
dumpbin /exports example-ffi.dll.lib
Produces:
Microsoft (R) COFF/PE Dumper Version 14.41.34123.0
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file example-ffi.dll.lib
File Type: LIBRARY
example-ffi.dll.lib : fatal error LNK1107: invalid or corrupt file: cannot read at 0x42A
The same command works if provided the static example-ffi.lib
instead of example-ffi.dll.lib
as an argument.