C Bindings: lib

lib

A lib declaration groups C functions and types that belong to a library.

@[Link("pcre")]
lib LibPCRE
end

Although not enforced by the compiler, a lib's name usually starts with Lib.

Attributes are used to pass flags to the linker to find external libraries:

  • @[Link("pcre")] will pass -lpcre to the linker, but the compiler will first try to use pkg-config.
  • @[Link(ldflags: "...")] will pass those flags directly to the linker, without modification. For example: @[Link(ldflags: "-lpcre")]. A common technique is to use backticks to execute commands: @[Link(ldflags: "`pkg-config libpcre --libs`")].
  • @[Link(framework: "Cocoa")] will pass -framework Cocoa to the linker (only useful in Mac OS X).

Attributes can be omitted if the library is implicitly linked, as in the case of libc.

To the extent possible under law, the persons who contributed to this workhave waived
all copyright and related or neighboring rights to this workby associating CC0 with it.
https://crystal-lang.org/docs/syntax_and_semantics/c_bindings/lib.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部