diff --git a/.zk/config.toml b/.zk/config.toml index 1b5fbbd..64bf697 100644 --- a/.zk/config.toml +++ b/.zk/config.toml @@ -81,7 +81,7 @@ template = "default.md" # Format used to generate links between notes. # Either "wiki", "markdown" or a custom template. Default is "markdown". -link-format = "wiki" +link-format = "[[{{path}}|{{title}}]]" # Indicates whether a link's path will be percent-encoded. # Defaults to true for "markdown" format and false for "wiki" format. #link-encode-path = true @@ -95,7 +95,7 @@ hashtags = true colon-tags = false # Enable support for Bear's #multi-word tags# # Hashtags must be enabled for multi-word tags to work. -multiword-tags = false +multiword-tags = true # EXTERNAL TOOLS diff --git a/.zk/notebook.db b/.zk/notebook.db index 0e59580..097aa6f 100644 Binary files a/.zk/notebook.db and b/.zk/notebook.db differ diff --git a/.zk/templates/default.md b/.zk/templates/default.md index cb44174..2266369 100644 --- a/.zk/templates/default.md +++ b/.zk/templates/default.md @@ -1,3 +1,9 @@ +--- +title: "{{title}}" +tags: +created: {{format-date now "%Y-%m-%d %H:%M"}} +--- + # {{title}} {{content}} diff --git a/notes/abi.md b/notes/abi.md new file mode 100644 index 0000000..643ca76 --- /dev/null +++ b/notes/abi.md @@ -0,0 +1,3 @@ +# ABI + + diff --git a/notes/ffi.md b/notes/ffi.md new file mode 100644 index 0000000..3f70d8d --- /dev/null +++ b/notes/ffi.md @@ -0,0 +1,3 @@ +# FFI + +FFI diff --git a/notes/multi-language-library.md b/notes/multi-language-library.md new file mode 100644 index 0000000..eee55fb --- /dev/null +++ b/notes/multi-language-library.md @@ -0,0 +1,74 @@ +--- +tags: dev +--- + +# Multi Language Library + +To create a library that can be used in multiple languages, the language that +is going to implement the library needs to support [[notes/ffi|FFI]] with the language +that the library is written in. + +With this in, we can use the following in our favor: + +- It's impossible that every language support every other language. +- For compatibility reasons, Almost every language supports C's [[notes/abi|ABI]] for their [[notes/ffi|FFI]]. +- Some compiled language has the avility to compile a C's _"dynamic library"_ (`.so` file in unix and `.dll` in windows). +- The [[notes/ffi|FFI]] use a _"dynamic library"_ to work. + +So, in conclusion: **we can use whatever language that supports compiling to C's ABI to build multi language libraries** + +## List of language that compiles to C's ABI + +### [[Go]] + +To produce a shared library, you need to compile it with compile with: `go build -buildmode=c-shared`. + +Note that the documentation says you need to specify with functions needs to be exported: + +> Build the listed main package, plus all packages it imports, into a C shared +> library. The only callable symbols will be those functions exported using a +> cgo //export comment. Requires exactly one main package to be listed. + +Example: + +src/go/main.go: + +```go +package main + +import "C" +import "fmt" + +//export helloLib +func helloLib(x C.int) { + fmt.Printf("Hello from Go! x=%d\n", x) +} + +func main() {} +``` + +src/c/main.c: + +```c +void helloLib(int); + +int main() { + helloLib(12345); +} +``` + +Building and running: + +```bash +go build -buildmode=c-shared -o libmy.so ./src/go/ +gcc -o test src/c/main.c libmy.so +./test +Hello from Go! x=12345 +``` + +Sources: + +- +- + +## List of languages that has support for FFI with C