Link to the Windows library outside the build folder

Is there a way to link to a library that is not in the current package path.

This link suggests placing everything under the local directory. Our packages are installed in some kind of repository elsewhere. I just want to point libpath to it in windows.

authors = ["Me"] links = "CDbax" [target.x86_64-pc-windows-gnu.CDbax] rustc-link-lib = ["CDbax"] rustc-link-search = ["Z:/Somepath//CPP/CDbax/x64/Debug/"] root = "Z:/Somepath//CPP/CDbax/x64/Debug/" 

But trying to build the -v load gives me

 package `hello v0.1.0 (file:///H:/Users/Mushfaque.Cradle/Documents/Rustc/hello)` specifies that it links to `CDbax` but does not have a custom build script 

From the build script manual, it will be shown that this should work. But I see that he did not add a path. However, moving lib to the local path bin\x68_64-pc-windows-gnu\ works.

Update Thanks to the answer below, I thought I was updating this to give final results of what works on my machine, so that others would find it useful.

In Cargo.toml add

 links = "CDbax" build = "build.rs" 

Although the build.rs file is missing, it seems that it (?) Otherwise complains about

 package `xxx v0.1.0` specifies that it links to `CDbax` but does not have a custom build script 

Vaelden then responds to creating a configuration file in .cargo

If this is a subdirectory, you do not need to put the links = tag in the parent box, although it is a dll; even with "cargo mileage". I assume that adds the dll path to the runtime

+6
source share
1 answer

I think the problem is that you are mistaken in the manifest of your project with a load of configuration.

  • Explicit is the Cargo.toml file at the root of your project. He describes your project.
  • The configuration of the load describes the specific settings for the load and allows, for example, redefining dependencies or, in your case, redefining build scripts. Cargo configuration files have a hierarchical structure :

Cargo allows you to have local configuration for a specific project or global configuration (e.g. git). Cargo also extends this hierarchical strategy ability. If, for example, in / home / foo / bar / baz, then the following configuration files will be probed for:

 /home/foo/bar/baz/.cargo/config /home/foo/bar/.cargo/config /home/foo/.cargo/config /home/.cargo/config /.cargo/config 

Using this structure, you can specify the local configuration for each project, and even possibly check it for version control. You can also specify a personal default with the configuration file in your home directory.

So, if you move the corresponding part:

 [target.x86_64-pc-windows-gnu.CDbax] rustc-link-lib = ["CDbax"] rustc-link-search = ["Z:/Somepath//CPP/CDbax/x64/Debug/"] root = "Z:/Somepath//CPP/CDbax/x64/Debug/" 

to any correct place for the load configuration file, it should work.

+6
source

Source: https://habr.com/ru/post/988653/


All Articles