Update
This commit is contained in:
parent
47bc34093a
commit
21468e47de
6 changed files with 88 additions and 2 deletions
|
|
@ -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
|
||||
|
|
|
|||
BIN
.zk/notebook.db
BIN
.zk/notebook.db
Binary file not shown.
|
|
@ -1,3 +1,9 @@
|
|||
---
|
||||
title: "{{title}}"
|
||||
tags:
|
||||
created: {{format-date now "%Y-%m-%d %H:%M"}}
|
||||
---
|
||||
|
||||
# {{title}}
|
||||
|
||||
{{content}}
|
||||
|
|
|
|||
3
notes/abi.md
Normal file
3
notes/abi.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# ABI
|
||||
|
||||
|
||||
3
notes/ffi.md
Normal file
3
notes/ffi.md
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
# FFI
|
||||
|
||||
FFI
|
||||
74
notes/multi-language-library.md
Normal file
74
notes/multi-language-library.md
Normal file
|
|
@ -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:
|
||||
|
||||
- <https://stackoverflow.com/questions/75035609/can-go-executable-be-used-as-a-dynamic-library>
|
||||
- <https://pkg.go.dev/cmd/go#hdr-Build_modes>
|
||||
|
||||
## List of languages that has support for FFI with C
|
||||
Loading…
Add table
Add a link
Reference in a new issue