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

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Rust Fundamentals

Lesson 39 of 50 · rust

Foreign Function Interface (FFI)

Duration: 20 minutes

Foreign Function Interface (FFI)\n\nRust can call C functions via extern "C" blocks and #[link].\n\nc\n/* hello.c */\n#include <stdio.h>\n\nvoid hello_from_c() {\n printf(\"Hello from C!\\n\");\n}\n\n\nrust\n// Cargo.toml\n[build-dependencies]\ncc = \"1.0\"\n\n\nrust\n// build.rs\nfn main() {\n cc::Build::new().file("src/hello.c").compile(\"hello\");\n}\n\n\nrust\nextern \"C\" {\n fn hello_from_c();\n}\n\nfn main() {\n unsafe { hello_from_c(); }\n}\n\n

Previous: Unsafe RustNext: Building a Simple Web Server