From c6f35a953a9736395744bd9a06f7abd65c7a1962 Mon Sep 17 00:00:00 2001 From: Jeremy Ruten Date: Tue, 16 Aug 2016 04:49:36 -0600 Subject: [PATCH] Fix code to trigger memcpy linker errors (#206) Fixes #205 --- blog/post/2015-09-02-set-up-rust.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blog/post/2015-09-02-set-up-rust.md b/blog/post/2015-09-02-set-up-rust.md index b07358a1..969736d7 100644 --- a/blog/post/2015-09-02-set-up-rust.md +++ b/blog/post/2015-09-02-set-up-rust.md @@ -132,7 +132,8 @@ Now we can try some Rust code: ```rust pub extern fn rust_main() { - let x = ["Hello", " ", "World", "!"]; + let x = ["Hello", "World", "!"]; + let y = x; } ``` When we test it using `make run`, it fails with `undefined reference to 'memcpy'`. The `memcpy` function is one of the basic functions of the C library (`libc`). Usually the `libc` crate is linked to every Rust program together with the standard library, but we opted out through `#![no_std]`. We could try to fix this by adding the [libc crate] as `extern crate`. But `libc` is just a wrapper for the system `libc`, for example `glibc` on Linux, so this won't work for us. Instead we need to recreate the basic `libc` functions such as `memcpy`, `memmove`, `memset`, and `memcmp` in Rust.