Including the dependency

As with using any library not provided by Prelude, the compiler has to know of the existence of the library. As we did in Chapter 8, The Rust Application Lifetime, we let the compiler know to expect an external library by including in the Cargo.toml file, as follows:

[dependency] 
libc = "0.2.0" 

The figure in quotes is the library version. This is useful to have in as it enables the compiled Rust application to only run against a particular version of the library, which guarantees the code required will be in the library. The downside is that in order to always ensure the library is available, the compiled binary will need to ship with that library. In this case (and this is the case for most external libraries), libc will need to be added.

We also need to include the following line to the source file where the functions will be called:

extern crate libc; 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset