# Undefined symbol when linking dylib written in rust

**URL:** https://discourse.cmake.org/t/undefined-symbol-when-linking-dylib-written-in-rust/10051
**Category:** Usage
**Created:** [February 11, 2024, 2:24am UTC](https://discourse.cmake.org/t/undefined-symbol-when-linking-dylib-written-in-rust/10051 "2024-02-11T02:24:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![danielmbomfim](https://discourse.cmake.org/user_avatar/discourse.cmake.org/danielmbomfim/32/4298_2.png) [@danielmbomfim](https://discourse.cmake.org/u/danielmbomfim)
#### Post date: [February 11, 2024, 2:24am UTC](https://discourse.cmake.org/t/undefined-symbol-when-linking-dylib-written-in-rust/10051/1 "2024-02-11T02:24:52Z")

</div>

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:

```rust
#[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

```c++
extern double multiply_rs(double a, double b);

```

```c++
#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

```auto
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.

---

<div class="post-metadata">

### Author: ![danielmbomfim](https://discourse.cmake.org/user_avatar/discourse.cmake.org/danielmbomfim/32/4298_2.png) [@danielmbomfim](https://discourse.cmake.org/u/danielmbomfim)
#### Post date: [February 11, 2024, 1:33pm UTC](https://discourse.cmake.org/t/undefined-symbol-when-linking-dylib-written-in-rust/10051/2 "2024-02-11T13:33:06Z")

</div>

Solved by updating the header file from `extern double multiply_rs(double a, double b);` to `extern "C" double multiply_rs(double a, double b);`
