Hi, i’m working on a side project trying to use rust to write a lib to be used on a turbo modules package from react native. I have written a very simple function in rust that multiply two numbers and return the result:
#[no_mangle]
pub extern "C" fn multiply_rs(x: f64, y: f64) -> f64 {
x * y
}
In my cmakelists file i have included that lib using the corrosion-rs tool to include the lib and then link it to the native library written in c++. I’m able to compile the code but when i tried to call the function a have received the error “undefined symbol: multiply_rs(double, double)”. I created a header file to declare the function i am calling and imported it on my cpp file
rust-mmkv.h
extern double multiply_rs(double a, double b);
#include "react-native-mmkv-rs.h"
#include "rust-mmkv.h"
namespace mmkvrs {
double multiply(double a, double b) {
double x = multiply_rs(a, b);
return x;
}
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1)
project(MmkvRs)
set (CMAKE_VERBOSE_MAKEFILE ON)
set (CMAKE_CXX_STANDARD 11)
include(FetchContent)
FetchContent_Declare(
Corrosion
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
GIT_TAG v0.4 # Optionally specify a commit hash, version tag or branch here
)
FetchContent_MakeAvailable(Corrosion)
corrosion_import_crate(MANIFEST_PATH ../rust-mmkv/Cargo.toml NO_LINKER_OVERRIDE)
add_library(react-native-mmkv-rs SHARED
../cpp/react-native-mmkv-rs.cpp
cpp-adapter.cpp
)
target_link_libraries(react-native-mmkv-rs PUBLIC rust-mmkv)
# Specifies a path to native header files.
include_directories(
../cpp
)
I don’t have much knowledge about cmake so i don’t know what i am doing wrong here…
Any help is much appreciated.