Currently, I am trying to figure out how to implement a network protocol module in Rust on RIOT, but I still can’t know how I can put the Rust code into the C application code. Specifically, my current setup is like this:
- I have a
rcoap.h
header file in thesys/include
that defines:
void hello(void);
- The module
sys/rcoap
:- Makefile:
include $(RIOTBASE)/Makefile.base
include $(RIOTMAKE)/cargo-settings.inc.mk
APPLICATION_RUST_MODULE = rcoap
USEMODULE += rust_riotmodules
# No need to set the Cargo features enabled through the general pseudomodules:
# They're added to the crate in cargo-targets.inc.mk no matter whether it's
# building the rust_riotmodules_standalone top level crate or an application
# crate.
include $(RIOTMAKE)/cargo-targets.inc.mk
- Code:
#![no_std]
#[no_mangle]
pub extern "C" fn hello() {
riot_wrappers::println!("Hello world");
}
- And a C application
examples/hello-rcoap
like this:
#include <stdio.h>
#include "rcoap.h"
int main(void)
{
hello();
return 0;
}
- I try to compile the application, but I still get the errors:
/usr/bin/ld: /media/duich1605/extras/projects/iot/rcoap/RIOT/examples/hello-rcoap/bin/native/application_hello-world/main.o: in function `main':
/media/duich1605/extras/projects/iot/rcoap/RIOT/examples/hello-rcoap/main.c:27: undefined reference to `hello'
collect2: error: ld returned 1 exit status
I have read rust modules inside the RIOT directory, but still can’t figure how I can link the header file and the rust source code together? Is there any specific configuration that allows me to do this?