Calling the Rust client libs from C


Hi there. I’m trying to get started developing an iOS app that will connect to the Maidsafe API. I know there is a Xamarin project going on, but I want to try calling the Rust libraries from C (or Objective-C) first.

Has anyone done this before? I couldn’t find any examples of it.

I checked out the safe_client_libs repo and tried using cbindgen to generate C header files for all the Rust functions. However cbindgen chokes on the FFI* classes and can’t generate headers for them, I’m not quite sure why. Then I learned about the auto-gen/c-include directory, which already contains all the header files I need. However, trying to import safe_app.h or safe_core.h results in a bunch of unknown type errors. I haven’t written C for a long time, so I may be missing something obvious. Does anyone have any pointers? My main.c file looks like this:

#include <stdint.h>
#include <stdio.h>
#include "c-include/safe_core.h"
#include "c-include/safe_app.h"

int main() {
    login("secret", "pass", 0, 0, 0);
    return 0;

(and I know calling login with 0s won’t work, I’m just trying to get something to compile right now)


Is your “c-include” subdirectory in the same directory as your main.c file? Or does the compiler otherwise know how to find the “c-include” directory?


Yeah, it is. Copied right from the safe_client_libs repo.


I don’t see those header files in the repo that you linked, but I think maybe you need to link to a library? See:


Yes, the auto-gen/c-include directory doesn’t get generated until you build the project, and it isn’t committed in git. I have built the safe_client_lib .dylibs and I am linking them with -L, but the compiler isn’t even making it to the link phase so that isn’t the problem.



Yes, the C headers should be already there. However, I have checked your sample code and you are right about the fact that it’s not possible to use them currently due to missing type definitions.

Here’s a tracking issue in JIRA:
We’ll fix this soon - thank you for reporting!