Skip to content

failed to link with link.exe failed: exit code: 1120 on Windows #544

@graydonlea

Description

@graydonlea

Though I Already solved this issue via build.rs to specify the link lib path explictly just now. But I suppose thats a little bit complicated, each time building duckdb on windows, you must always write these template codes.

// build.rs
fn main() {
    println!("cargo:rustc-link-search=native=C:\\Windows\\System32");
    println!("cargo:rustc-link-lib=Rstrtmgr");
}

Issue

Failed to build duckdb demo on Windows, even with the simplest example of duckdb docs;

I reviewed past issues and found that most suggest installing MS VS Build Tools, but in fact, this did not solve my issue.

Im sure that I have installed MSVC and its toolchain, and configured them in the environment variables.

Below is the env path.

C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.44.35207\bin\Hostx64\x64

I added both to the environment variables and built the installation via cargo add duckdb --features bundled, but it still not works. The error message is as follows.

Error Messages

error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\Y\\AppData\\Local\\Temp\\rustc7pLY8m\\symbols.o" "<55 object files omitted>" "C:\\Users\\Y\\Desktop\\demo\\target\\debug\\deps/{libduckdb-b3f8362446aea317.rlib,libsmallvec-c183f9d47da38243.rlib,libcast-49db356ef74b85f3.rlib,librust_decimal-3a5b9cbf4877a907.rlib,libserde-22d9db03cb63b99f.rlib,libarrayvec-d50e6e157ab9318a.rlib,libfallible_streaming_iterator-04f60b605fc0f73f.rlib,libfallible_iterator-68563fc10ffcf3b8.rlib,libstrum-8e30c85333ea2765.rlib,libhashlink-3ba134715094e3cb.rlib,libarrow-5ac1a72fe2a27e5d.rlib,libarrow_row-e8aed7be06733ce6.rlib,libarrow_string-7973c0bda726cc56.rlib,libregex-710eef4d38ee3fd6.rlib,libregex_automata-db83f4512e1b5c7d.rlib,libaho_corasick-24adfb8458d9ade7.rlib,libregex_syntax-b6714b60b7bc7e4a.rlib,libmemchr-da6ba839bbe8ebcc.rlib,libarrow_cast-1a27c9e1a3dc2694.rlib,libatoi-e6ebe25009fa1943.rlib,libryu-37203d2c467f8da8.rlib,libbase64-0b360acb9dc29ba9.rlib,libcomfy_table-251418f61f10dac3.rlib,libunicode_segmentation-0b8b78906ba6799f.rlib,libunicode_width-5ad620de9423ed41.rlib,liblexical_core-a899d107d4a1caf3.rlib,liblexical_write_float-41eba6196db745d8.rlib,liblexical_write_integer-75f049f9e63a6664.rlib,liblexical_parse_float-43b8fed49b79bfbd.rlib,liblexical_parse_integer-8bdd1cf08a8114d2.rlib,liblexical_util-baf5b3dfc43aa25a.rlib,libstatic_assertions-da84d677a2cbb685.rlib,libarrow_arith-79812951151e328c.rlib,libarrow_ord-4db3a0b5e663b54b.rlib,libarrow_select-55fc1a24d0d3ef75.rlib,libarrow_array-01ea262a82a871bf.rlib,libahash-94b54058c337bbde.rlib,libgetrandom-2a89a66638c7e38e.rlib,libonce_cell-84b94b97ea24f67b.rlib,libzerocopy-e1dffdfb07107702.rlib,libhashbrown-5a1847c4e38fdd05.rlib,libfoldhash-c7e1bc489b06a6d3.rlib,libchrono-d9f9b240257d9e4e.rlib,libwindows_link-71c4caf817584dd3.rlib,libarrow_data-a31197f5464dcbdc.rlib,libarrow_schema-f4ee27f94a7e2fd1.rlib,libbitflags-05ed3484cc55db94.rlib,libarrow_buffer-a0c15988dc061bdc.rlib,libbytes-441da4d76b13cbcb.rlib,libhalf-747f7d890291de0f.rlib,libcfg_if-3d39ba26ec35ebac.rlib,libnum-f0aa498cc9e9b9e3.rlib,libnum_iter-b389ef6f565c05d2.rlib,libnum_rational-1b7cd3981135e2f8.rlib,libnum_complex-2537c84c16f51dd3.rlib,libnum_bigint-737a93fc7600053a.rlib,libnum_integer-e7cba3faece1f759.rlib,libnum_traits-1701bc9abe802865.rlib,liblibduckdb_sys-26b80393c1b83bef.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" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:C:\\Users\\Y\\Desktop\\demo\\target\\debug\\build\\libduckdb-sys-504c6af2e068003e\\out" "/LIBPATH:C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.44.35207\\atlmfc\\lib\\x64" "/OUT:C:\\Users\\Y\\Desktop\\demo\\target\\debug\\deps\\demo.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\Y\Desktop\demo\target\debug\deps\demo.lib and obj C:\Users\Y\Desktop\demo\target\debug\deps\demo.exp␍
          liblibduckdb_sys-26b80393c1b83bef.rlib(1556d1d208655402-ub_src_common.o) : error LNK2019: unresolved external symbol RmStartSession,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) references this symbol ␍
          liblibduckdb_sys-26b80393c1b83bef.rlib(1556d1d208655402-ub_src_common.o) : error LNK2019: unresolved external symbol RmEndSession,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) references this symbol ␍
          liblibduckdb_sys-26b80393c1b83bef.rlib(1556d1d208655402-ub_src_common.o) : error LNK2019: unresolved external symbol RmRegisterResources,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) references this symbol ␍
          liblibduckdb_sys-26b80393c1b83bef.rlib(1556d1d208655402-ub_src_common.o) : error LNK2019: unresolved external symbol RmGetList,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) references this symbol ␍
          C:\Users\Y\Desktop\demo\target\debug\deps\demo.exe : fatal error LNK1120: 4 unresolved externals ␍

To Reproduce

This issue is consistently reproducible on my Windows system. First, I installed MS Visual Studio C++ Build Tools and added the paths for CMake, Cl, etc., to the environment variables. Then, I installed the MSVC toolchain for Rust 1.88.0 and created a project. I added duckdb using the command cargo add duckdb --features bundled, but unfortunately, I always encounter an error during cargo build.

Perhaps I missed some critical steps, but the above is the complete process to reproduce the issue on my Windows system.

Below is the code

use duckdb::{params, Connection, Result};
use duckdb::arrow::record_batch::RecordBatch;
use duckdb::arrow::util::pretty::print_batches;

#[derive(Debug)]
struct Person {
    id: i32,
    name: String,
    data: Option<Vec<u8>>,
}

fn main() -> Result<()> {
    let conn = Connection::open_in_memory()?;

    conn.execute_batch(
        r"CREATE SEQUENCE seq;
          CREATE TABLE person (
                  id              INTEGER PRIMARY KEY DEFAULT NEXTVAL('seq'),
                  name            TEXT NOT NULL,
                  data            BLOB
                  );
         ")?;
    let me = Person {
        id: 0,
        name: "Steven".to_string(),
        data: None,
    };
    conn.execute(
        "INSERT INTO person (name, data) VALUES (?, ?)",
        params![me.name, me.data],
    )?;

    let mut stmt = conn.prepare("SELECT id, name, data FROM person")?;
    let person_iter = stmt.query_map([], |row| {
        Ok(Person {
            id: row.get(0)?,
            name: row.get(1)?,
            data: row.get(2)?,
        })
    })?;

    for person in person_iter {
        println!("Found person {:?}", person.unwrap());
    }

    // query table by arrow
    let rbs: Vec<RecordBatch> = stmt.query_arrow([])?.collect();
    print_batches(&rbs);
    Ok(())
}

Rustc ver

rustc 1.88.0 (6b00bc388 2025-06-23)
binary: rustc
commit-hash: 6b00bc3880198600130e1cf62b8f8a93494488cc
commit-date: 2025-06-23
host: x86_64-pc-windows-msvc
release: 1.88.0
LLVM version: 20.1.5

OS:

Windows11 24h2

DuckDB Version:

1.3.2

DuckDB Client:

Rust

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions