Skip to content

Conversation

@maemon4095
Copy link
Contributor

Fix libduckdb-sys build failure on Windows related to #268 (possibly also related to #482 and #413).

Added a line to libduckdb-sys/build.rs to specify the encoding when compiling C code.

@wyhaya
Copy link

wyhaya commented Apr 13, 2025

In my testing, this PR resolves a portion of the issues.

There are still some other errors:

error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\dev\\AppData\\Local\\Temp\\rustcGnutTC\\symbols.o" "<11 object files omitted>" "C:\\Users\\dev\\Desktop\\duckdb-rs\\target\\debug\\deps/{liblibduckdb_sys-626df3e6a568ec49.rlib}.rlib" "<sysroot>\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib/{libstd-*,libpanic_unwind-*,libwindows_targets-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libunwind-*,libcfg_if-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "kernel32.lib" "kernel32.lib" "advapi32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:C:\\Users\\dev\\Desktop\\duckdb-rs\\target\\debug\\build\\libduckdb-sys-940f8639da89845a\\out" "/OUT:C:\\Users\\dev\\Desktop\\duckdb-rs\\target\\debug\\examples\\main.exe" "/OPT:REF,NOICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\libstd.natvis"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note:    Creating library C:\Users\dev\Desktop\duckdb-rs\target\debug\examples\main.lib and object C:\Users\dev\Desktop\duckdb-rs\target\debug\examples\main.exp␍
          liblibduckdb_sys-626df3e6a568ec49.rlib(6e5d8cd65011422c-ub_src_common.o) : error LNK2019: unresolved external symbol RmStartSession referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl duckdb::AdditionalLockInfo(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (?AdditionalLockInfo@duckdb@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@3@@Z)␍
          liblibduckdb_sys-626df3e6a568ec49.rlib(6e5d8cd65011422c-ub_src_common.o) : error LNK2019: unresolved external symbol RmEndSession referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl duckdb::AdditionalLockInfo(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (?AdditionalLockInfo@duckdb@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@3@@Z)␍
          liblibduckdb_sys-626df3e6a568ec49.rlib(6e5d8cd65011422c-ub_src_common.o) : error LNK2019: unresolved external symbol RmRegisterResources referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl duckdb::AdditionalLockInfo(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (?AdditionalLockInfo@duckdb@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@3@@Z)␍
          liblibduckdb_sys-626df3e6a568ec49.rlib(6e5d8cd65011422c-ub_src_common.o) : error LNK2019: unresolved external symbol RmGetList referenced in function "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl duckdb::AdditionalLockInfo(class std::basic_string<wchar_t,struct std::char_traits<wchar_t>,class std::allocator<wchar_t> >)" (?AdditionalLockInfo@duckdb@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@3@@Z)␍
          liblibduckdb_sys-626df3e6a568ec49.rlib(337470f5afaaf2c3-entropy_poll.o) : error LNK2019: unresolved external symbol BCryptGenRandom referenced in function mbedtls_platform_entropy_poll␍
          C:\Users\dev\Desktop\duckdb-rs\target\debug\examples\main.exe : fatal error LNK1120: 5 unresolved externals␍


error: could not compile `libduckdb-sys` (example "main") due to 1 previous error

This error can be fixed by the following code (from AI):

println!("cargo:rustc-link-lib=dylib=Rstrtmgr");
println!("cargo:rustc-link-lib=dylib=Bcrypt");

For me, this resolved all the errors I was encountering while building libduckdb-sys on Windows.

@maemon4095
Copy link
Contributor Author

I found the following some lines in CMakeList.txt https://github.com/duckdb/duckdb/blob/7c039464e452ddc3330e2691d3fa6d305521d09b/src/CMakeLists.txt#L33

These lines add Ws2_32, Rstrtmgr and Bcrypt to the link targets when using MSVC.
So I think I need to link these libraries in order to build.
However, I don't know why the build succeeds in my environment without linking these libraries.

@Maxxen
Copy link
Member

Maxxen commented May 23, 2025

Thanks!

@Maxxen Maxxen merged commit bfe98e6 into duckdb:main May 23, 2025
4 checks passed
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 this pull request may close these issues.

3 participants