O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connecting external libraries to Rust code

It's more likely that we'll want to link some pre-existing library written in C to our Rust code. The needed code on the Rust extends a bit on the previous example. We'll take the classic Unix ncurses library, which is used to display graphics, like text on the console. The first task is to define the external functions we'd like to use, supplying the extern block with a link attribute that tells which library the functions are coming from. The ncurses library has tons of functions, but we'll just use a couple in this example.

If you have a reasonable Unix-like operating system, you might want to look at the ncurses manual page by commanding man ncurses. Let's start by building a trivial program: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required