carp-lang / Carp

A statically typed lisp, without a GC, for real-time applications.
Apache License 2.0
5.47k stars 173 forks source link

Using other C frameworks. Documentation request #949

Closed interstar closed 3 years ago

interstar commented 3 years ago

Carp looks really exciting. Congratulations guys.

I mainly try to write Clojure when I can. But I also do audio which currently means C++. I've been looking for a way to use Clojure or a Clojure-like Lisp for that, and Carp looks very promising.

But for these applications I need to interact with the VCV Rack (https://vcvrack.com/manual/PluginDevelopmentTutorial) and NanoVG libraries. Or with JUCE (https://juce.com/learn/documentation) and the Steinberg VST API (https://www.steinberg.net/en/company/developers.html)

I see how out-of-the-box Carp works with SDL. But I'm not sure how to set it up to work with one of these alternative frameworks.

Is there documentation or a tutorial for that? If not, I propose that this would be really useful.

hellerve commented 3 years ago

This seems like it’s very related to #534! The short answer is that the current docs are very much insufficient. Maybe looking at things like the wrappers around sqlite3, Lua, or libhydrogen could be instructive (though, as the main author, I cannot any warranty on code quality 😸 )?

interstar commented 3 years ago

Thanks. I'll have a look at these.

I guess a couple of questions that occur to me. Partly because I'm pretty hazy about C development.

When you wrap are you talking about something that calls dynamic C libraries that are installed on the system beforehand? Or static libraries that have to be linked at compile-time and which are (presumably) stored in your project?

In general, I think I'm going to want to create self-contained binaries. So, for example, when I compile the Carp examples like Reptile, is the final binary still depending on the SDL libraries being separately installed on the machine?

If I want to put a static lib file into my project to be included in the carp build, where should I put it?

eriksvedang commented 3 years ago

The carp compiler emits a single C file to disk, which it will compile using a compiler installed on your system. From this point on there's no trace of "Carp" left, it's all C. So any library you want to link to, dynamic or static, will have to be available so that the C compiler can find it.

If you want to see how Carp invokes the compiler, evaluate (Project.config "echo-compiler-cmd" true) in the repl (or put it at the top of your .carp source file. You can always experiment with the exact invocation from the command line to see if you can get it to build. Generally, tools like pkg-config and packet managers will be of great help when using C libraries, due to the non-standarized ways to install those.

eriksvedang commented 3 years ago

Closing duplicate.