this is essentially passing a -lsqlite3 flag to the linker, the behavior of which is actually linker dependent. for msvc on windows, it will look for a library file named sqlite3.lib.
for most platforms, the default behavior is to link against the static library first if it exists. if you want to ensure the static library is used, it can be explicitly specified:
basically there are two possibilities: the library file name is wrong, or the search directory path is wrong.
for the first problem, how did you build the library? can you double check the libsqlite3.a file is a valid static library?
I would suggest you use the cc crate to build the library, if you have to build it from source yourself. a better solution would be just use the sqlite3 crate (or sqlite3-sys, or even sqlite3-src).
for the second, how did you calculated BUILD_DIR? if you build the library in the build script, you should put the artifact inside the directory as specified by cargo in the OUT_DIR environment variable. also, is BUILD_DIR a relative path or absolute path?
maybe your BUILD_DIR is wrong but the first case "happens" to work because your host system has a libsqlite3.so installed. in other words, it might seem to work but didn't do what you expected.
at last, you can always check the full linker command line by setting the --print link-args compiler flag, for example:
you are supposed to calculate the absolute paths using the CARGO_MANIFEST_DIR environment variable. e.g.
// do NOT use relative path like this:
println!("cargo::rustc-link-search=libraries");
// NOR this:
println!("cargo::rustc-link-search=./libraries");
// instead, DO this:
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo::rustc-link-search={}/libraries", dir);
// or this:
let dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
println!("cargo::rustc-link-search={}", dir.join("libraries").display());
note, this directory is the current working directory cargo sets when executing the per-package build script, but it is NOT specified as the working directory when cargo invokes the compiler.
I can't find the exact documentation, but from my experience, the working directory for the compiler is the workspace directory, which is NOT per-package.
this means if you use relative paths (relative to CARGO_MANIFEST_DIR) in your build script, it will only work when you compile the crate standalone and your crate is not a member of a multi-package workspace. specifically, it will NOT work when the crate is used as a dependency by other crates.