S
14d ago

C Wrapper API for FFI

I want to build a Dart package that will interact with the Rive-CPP library indirectly through this C wrapper to access Rive file contents. Dart doesn't have native support for directly interacting with C++ code, so the C wrapper will act as an intermediary layer that exposes the functionality of the Rive-CPP library in a way that Dart can understand through FFI.

Can someone show me some light on how to do it? I am quite new to the C/C++ environment.

Here is what I have done already -
1. Compiled the `rive-cpp` project with the command build.sh release, and it generated the static library librive.a
2. I created a wrapper C header and CPP code that exposes C API, and when I am building it and linking to the static library, I get the below error.

Am I going in the right direction? What am I doing wrong here?

For what it's worth, below is the CMakeLists.txt for my C wrapper.

cmake_minimum_required(VERSION 3.29)
project(wrapper VERSION 1.0.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 11)

# Add the directory containing the 'rive' directory to the include directories
include_directories(${CMAKE_CURRENT_SOURCE_DIR})

# Add the rivefile shared library target
add_library(rivefile SHARED rivefile.cpp)

# Set public header for the shared library
set_target_properties(rivefile PROPERTIES
  PUBLIC_HEADER "rivefile.h"
  VERSION ${PROJECT_VERSION}
  SOVERSION 1
  OUTPUT_NAME rivefile
)

# Link the rive library with the rivefile library
target_link_libraries(rivefile PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/../librive/librive.a")

Please let me know if any more information is needed. I'll be happy to share.

Join the discussion
Join Rive to reply ⇧ J