Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Foreign Function Interface (FFI) | Rust Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 39 of 50

·rust

Foreign Function Interface (FFI)

20 minutes

Course progress78%

Foreign Function Interface (FFI)

Rust can call C functions via extern "C" blocks and #[link].

/* hello.c */
#include <stdio.h>

void hello_from_c() {
    printf(\
"Hello from C!\ \"); }
// Cargo.toml
[build-dependencies]
cc = \"1.0\"
// build.rs
fn main() {
    cc::Build::new().file("src/hello.c").compile(\"hello\");
}
extern \"C\" {
    fn hello_from_c();
}

fn main() {
    unsafe { hello_from_c(); }
}
Make it stickPractice what you've learned1 quiz · 1 practical test · Optional activities from Rust FundamentalsBrowse activities
Previous lessonUnsafe RustContinue to lesson 40Building a Simple Web ServerBack to Rust Fundamentals curriculum