Linking to C Libraries

Hi, Is there examples of linking UNO to natice c-libraries? I found that Foreign Code works for Java and Objective-C, and also CPLUSCPLUS, I did not find any for c libraries. thanks fkao

Hello, and thanks for the post!

Documentation in this area is a bit lacking, so I’ve created an internal issue to improve this. We do this all the time internally, so it’s certainly possible. Basically, code blocks inside @{...@} or extern<type> "..." are interpreted as native code (C++ when targeting iOS or Android). Here’s a guide to get you started.

On top of that, there are a bunch of attributes you can use on a class or method to control header includes and library linking. The ones you’ll need are:

[Require("LinkDirectory", "@('some/relative/path':Path)")] // used to add an -L flag to the C++ compiler
[Require("LinkLibrary", "mylibrary")] // -lmylibrary
[Require("IncludeDirectory", "@('some/relative/path':Path)")] // -I flag
[Require("Source.Include", "someheader.h")] // Adds `#include <someheader.h>` to the C++ code generated from the Uno class

Let us know how it works out for you!